主题:求助,谁能帮我看看那里出错了
一个排序的算法,想用汇编写
for(i=0;i<9;i++)
{
for(int j=i+1;j<9;j++)
{
if (a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
把只些代码改用汇编写...
我写的代码...
.model small
.stack
.data
a db 11h,15h,45h,34h,7h,65h,16h,33h
temp db ?
i equ $-a
j db ?
.code
.startup
mov cx,0 ; cx相当与外循环的i
.while cx<i
push cx
mov ax,[si+cx]
.while cx<i ;相当于内循环的j
.if ax<[si+cx+1]
mov temp,ax
mov ax,[si+cx+1]
mov [si+cx+1],temp
.endif
inc cx
.endw
pop cx;i
inc cx
.endw
.exit 0
end
但怎么也调不通...
还有一个问题是,如何实现C++混合汇编?
用刚才那个为例
#include<iostream>
using namespace std;
int main()
{
int a[]={11,5,34,67,34,69,32,2,23};
for(int i=0;i<9;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
//上面的for用的显示排序前的输出
int temp;
[color=FF0000] for(i=0;i<9;i++)
{
for(int j=i+1;j<9;j++)
{
if (a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}[/color]
for( i=0;i<9;i++)
{
cout<<a[i]<<" ";
}
//排序后的输出
return 0;
}
红色的排序代码应如何修改,用汇编实现?如何写入口参数和出口参数?
for(i=0;i<9;i++)
{
for(int j=i+1;j<9;j++)
{
if (a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
把只些代码改用汇编写...
我写的代码...
.model small
.stack
.data
a db 11h,15h,45h,34h,7h,65h,16h,33h
temp db ?
i equ $-a
j db ?
.code
.startup
mov cx,0 ; cx相当与外循环的i
.while cx<i
push cx
mov ax,[si+cx]
.while cx<i ;相当于内循环的j
.if ax<[si+cx+1]
mov temp,ax
mov ax,[si+cx+1]
mov [si+cx+1],temp
.endif
inc cx
.endw
pop cx;i
inc cx
.endw
.exit 0
end
但怎么也调不通...
还有一个问题是,如何实现C++混合汇编?
用刚才那个为例
#include<iostream>
using namespace std;
int main()
{
int a[]={11,5,34,67,34,69,32,2,23};
for(int i=0;i<9;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
//上面的for用的显示排序前的输出
int temp;
[color=FF0000] for(i=0;i<9;i++)
{
for(int j=i+1;j<9;j++)
{
if (a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}[/color]
for( i=0;i<9;i++)
{
cout<<a[i]<<" ";
}
//排序后的输出
return 0;
}
红色的排序代码应如何修改,用汇编实现?如何写入口参数和出口参数?