2016-06-12 11 views
1

このプログラムは、ユーザー入力(デポ&引き出し)を取ることによって、ユーザーの最終残高を計算します。プログラムは最終残高を正しく計算しますが、アーバインライブラリから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

整数を印刷するために、値ではなくポインタを渡します。 'mov eax、OFFSET finalBalance'の代わりに' mov eax、finalBalance'を実行します – Jester

答えて

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