【发布时间】:2017-10-03 18:21:18
【问题描述】:
我有以下 c 汇编代码,它按降序对数组进行排序,我已经使用 8086emu 对其进行了测试,它可以 100% 工作,但在 Visual Studio 中它给了我错误的结果和错误。任何想法或如何解决这个问题。
我的代码:-
#include "stdafx.h"
#include <iostream>
using namespace std;
void main(void)
{
short *arr;
arr = new short[10];
cout << "please enter the array elements" << endl;
for (int i = 0; i < 10; i++)
{
cin >> arr[i];
}
short *p;
p = arr;
_asm{
START:
mov cx, 9
mov esi, p
LABEL2 :
MOV ax, [esi]
CMP ax, [esi + 2]
JGE LABEL1
MOV bx, [esi + 2]
MOV word ptr[esi], bx
MOV word ptr[esi + 2], ax
JMP START
LABEL1 :
inc esi
inc esi
LOOP LABEL2
}
for (int i = 0; i < 10; i++)
{
cout << arr[i] << endl;
}
}
【问题讨论】:
-
组装完成了多远?你做了什么来调试这个?
-
@PaulBentley 我没有调试过,它在输入数组元素后直接出现,但是 ASM 块内的相同代码适用于 Masm 和 emu。
-
loop可能会减少和检查ecx,而不仅仅是较低的单词 (cx)。如果您使用mov ecx,9而不是mov cx,9会怎样? -
@Michael Ohhhhhhhh 谢谢你的工作,谢谢
标签: arrays assembly inline-assembly emu8086