该程序通过获取用户输入(存款和取款)来计算用户的最终余额。程序正确计算最终余额但是当我使用来自Irvine库的WriteInt打印出来时,无论最终余额是多少,它都会打印+4218884。有什么想法吗?
INCLUDE Irvine32.inc
.data
initialBalance DWORD 1000
finalBalance DWORD 0
numOfDeposit DWORD 0
numOfWithDraw DWORD 0
msgDeposit BYTE "How many deposit?", 0
msgWithdraw BYTE "How many withdraw?", 0
msgEnterD BYTE "ENTER DEPOIST: ", 0
msgEnterW BYTE "ENTER WITHDRAW: ", 0
msgFinalBalance BYTE "Your final balance is: ", 0
.code
main proc
mov ebx, initialBalance ;move the initial balance to the ebx register
mov edx, OFFSET msgDeposit ;move the address of msgDeposit to edx for printing it out
call WriteString ;print the msgDeposit out
call ReadInt ;read the number of deposits user made
mov numOfDeposit, eax ;store that number in umOfDeposit
mov edx, OFFSET msgWithdraw ;move the address of msgWithdraw to eax for printing it out
call WriteString ;print the msgWithdraw out
call ReadInt ;read the number of withdraws user made
mov numOfWithdraw, eax ;store that number in numOfWithdraw
mov ecx, numOfDeposit ;sets the counter for depoLoop
mov eax, initialBalance ;move initial balance to eax
add finalBalance, eax ;move element in eax to final balance
depositLoop:
mov edx, OFFSET msgEnterD ;move the address of the msg, "enter deposit", to edx for print it out
call WriteString ;print the message out
call ReadInt ;read a deposit that the user made
add finalBalance, eax ;add the deposit to the final balance.
loop depositLoop ;repeat the loop
mov ecx, numOfWithDraw ;sets the counter for withdrawLoop
withdrawLoop:
mov edx, OFFSET msgEnterW ;"ENTER WITHDRAW"
call WriteString ;print the message out
call ReadInt ;read a withdraw that the user made
sub finalBalance, eax ;substract from final balance
loop withdrawLoop ;repeat the loop
mov edx, OFFSET msgFinalBalance ;move the address of the msg, "Your final balance is: ", to edx for printing
call WriteString ;print the message out
mov eax, OFFSET finalBalance ;move the final balance to eax for printing it out
call WriteInt ;print the final balance out
call Crlf
call WaitMsg ;Displays a message and waits for a key to be pressed.
exit
main endp
end main
答案 0 :(得分:2)
mov eax, OFFSET finalBalance ;move the final balance to eax for printing it out
call WriteInt ;print the final balance out
call Crlf
尝试:
mov eax, finalBalance