2016-06-12 2 views
1

Эта программа рассчитывает окончательный баланс пользователя, вводя пользовательский ввод (депозит &). Программа правильно вычисляет окончательный баланс, но когда я распечатываю его с помощью WriteInt из библиотеки Irvine, он печатает +4218884 независимо от значения, которое имеет окончательный баланс. Любые идеи почему?Печать Окончательный баланс Сборка (Irvine)

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' do' 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        

Try:

mov eax, finalBalance

Смежные вопросы