有人可以帮我弄清楚为什么这段代码不起作用?我在比较指令的3行收到错误。这是为了上课,我必须自学,所以任何帮助将不胜感激。这个赋值用于传递值和分析堆栈的章节。
; procedure to compute the minimum of 3 DWORD values
; The MIN is calculated, returned in eax, and displayed.
; Other registers are unchanged.
.386 ; assembler use 80386 instructions
.MODEL FLAT ; use modern standard memory model
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h ; header file for input/output
cr EQU 0dh ; carriage return
Lf EQU 0ah ; line feed
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
num1 DWORD 0
num2 DWORD 0
num3 DWORD 0
directions BYTE cr, Lf, 'Please enter 3 numbers.', cr, Lf
BYTE 'This program will then report the minimum',cr,Lf, 0
numlabel BYTE cr,Lf,Lf, 'The MIN is: '
minValue BYTE 16 DUP (?), cr,Lf,0
.CODE ; program code
MIN3 PROC NEAR32
push ebp ; save base pointer
mov ebp,esp ; copy stack pointer
push ebx ; save registers
push ecx
push edx
cmp num1, num2
jg second
cmp num1, num3
jg second
mov eax, num1
jmp retpop
second:
cmp num2, num3
jg third
mov eax, num2
jmp retpop
third:
mov eax, num3
jmp retpop
retpop:
pop edx ; restore registers
pop ecx
pop ebx
pop ebp ; restore base pointer
ret ; return
MIN3 ENDP
_start: ; program entry point
output directions ; display directions
input minValue,16 ; get number
atod minValue ; convert to integer
mov num1, eax
input minValue,16 ; get number
atod minValue ; convert to integer
mov num2, eax
input minValue,16 ; get number
atod minValue ; convert to integer
mov num3, eax
call MIN3 ; find minimum value, ret eax
dtoa minValue, eax
output numlabel
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start
END
答案 0 :(得分:3)
x86
没有支持2个内存操作数的cmp
指令版本。因此,cmp num1, num2
无效,您应将其中一个加载到寄存器中并将其用于比较,例如:
mov edx, num1
cmp edx, num2
你应该注意汇编程序试图通过错误消息告诉你什么,并且还有方便的指令集参考。