首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印最终余额结转装配件(欧文)

打印最终余额结转装配件(欧文)
EN

Stack Overflow用户
提问于 2016-06-13 00:45:48
回答 1查看 569关注 0票数 1

这个程序通过接受用户的输入(存取款)来计算用户的最终余额。该程序正确地计算了最终余额,但是当我使用Irvine库中的WriteInt将其打印出来时,无论最终余额的值是什么,它都会打印+4218884。你知道为什么吗?

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2016-06-13 03:39:15

代码语言:javascript
复制
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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37776734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档