簡單的裝配程序可以吐出兩個用戶輸入數字中較大的一個。我無法正確輸出輸出。例如,如果我輸入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'影響,根據以下鏈接:http://flylib.com/books/en/2.265.1.27/1/ 從鏈接引用: 輸入宏只更改指定目標處的內存。它不會更改任何寄存器內容,包括標誌寄存器。 –