我正在使用 C++ 和汇编语言(8086)编写一个混合程序,以从数组中找到最小的数字。这是我的代码
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
__int16 a[5],x,y,res;
int i,j;
y=999;
cout<<"\n Enter 5 Numbers:";
for(i=0;i<5;i++)
{
cin>>a[i];
}
_asm{
mov bx,y
}
//Finding smallest
for(i=0;i<5;i++)
{
x=a[i];
_asm{
mov ax,x
cmp ax,bx
jge nxt
mov bx,ax
nxt:
}
}
_asm{
mov res,bx;
}
cout<<"\n Smallest Element:"<<res;
getch();
}
上面的代码是用 Visual Studio 2010 编写的,似乎运行良好。但是当我为 Turbo c++ 更新相同的代码时(即将“iostream”更改为“iostream.h”,删除“using namespace std;”,将“__int16”更改为“int”等),它不起作用。执行后产生的答案是错误的。
这是我的 TC++ 程序
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],x,y,res;
int i,j;
y=999;
cout<<"\n Enter 5 Numbers:";
for(i=0;i<5;i++)
{
cin>>a[i];
}
_asm{
mov bx,y
}
//Finding smallest
for(i=0;i<5;i++)
{
x=a[i];
_asm{
mov ax,x
cmp ax,bx
jge nxt
mov bx,ax
}
nxt:
}
_asm{
mov res,bx;
}
cout<<"\n Smallest Element:"<<res;
getch();
}
为什么 TC++ 和 Visual Studio 10 没有给出相同的答案?