【发布时间】:2017-10-19 06:49:27
【问题描述】:
用于输出两个用户输入数字中较大者的简单汇编程序。我无法正确输出。例如,如果我输入 45 和 55,最大值将是 55,但是当我尝试反向 55 和 45(答案应该仍然是 55)时,我得到 45。看起来这个程序只输出输入的第二个值和存储在 EAX。非常感谢任何帮助。
.586
.MODEL FLAT
INCLUDE io.h
.STACK 4096
.DATA
value1 DWORD ?
value2 DWORD ?
prompt1 BYTE "Enter the first number", 0
prompt2 BYTE "Enter the second number", 0
string BYTE 40 DUP (?)
resultLbl BYTE "The maximum value you entered was:", 0
.CODE
_MainProc PROC
input prompt1, string, 40 ;get user input value1
atod string ;convert input (ASCII) to integer
mov ebx, eax
input prompt2, string, 40 ; repeat for value2
atod string
mov value2, eax
cmp eax, ebx ;compare user inputs
jg greater_than ;jump conditional if value 1 is greater then value 2
greater_than: ;condition if greater than ouput
dtoa value1, eax ;decimal to ASC for output of
integer value stored at ebx
output resultLbl, value1 ;output value 1
jmp exit
less_than: ;condition if less than ouput
dtoa value1, eax
output resultLbl, value2 ;else output value 2
jmp exit
exit: ;quit jump ;end if/else conditional
mov eax, 0 ;clear memory
mov ebx, 0
ret
_MainProc ENDP
END
【问题讨论】:
-
调试它。很可能 ebx 在函数调用中被覆盖。将其存储在内存中,而不是寄存器中
-
@SamiKuhmonen 没有寄存器受
input影响,根据以下链接:flylib.com/books/en/2.265.1.27/1 引用链接:输入宏仅更改指定目标的内存。它不会改变任何寄存器内容,包括标志寄存器。