Question: Need help with assembly coding using the asmlib.inc library I have two codes one called balances.asm and one called main.asm the code will compile but

Need help with assembly coding using the asmlib.inc library I have two codes one called balances.asm and one called main.asm the code will compile but the output is all wrong and will just go on forever unless stopped
(output)
Enter your balance 1000
Enter the interest rate (like 5.0)5.0
Enter the number of years 10
Year: 1: $6
Year: 2: $6
Year: 3: $6
Year: 4: $-nan(ind)
Year: 5: $-nan(ind)
Year: 6: $-nan(ind)
Year: 7: $-nan(ind)
Year: 8: $-nan(ind)
Year: 9: $-nan(ind)
Year: 10: $-nan(ind)
Year: 11: $-nan(ind)
Year: 12: $-nan(ind)
Year: 13: $-nan(ind)
Year: 14: $-nan(ind)
Year: 15: $-nan(ind)
Year: 16: $-nan(ind)
Year: 17: $-nan(ind)
Year: 18: $-nan(ind)
(balances.asm)
INCLUDE asmlib.inc
.data
yearStr BYTE "Year: ",0
colonStr BYTE ": ",0
dollarStr BYTE "$",0
newlineStr BYTE 13,10,0
.code
crlf PROC
mov edx, OFFSET newlineStr
call writeString
ret
crlf ENDP
; yearlyBalance: Calculates and outputs the yearly balance for a given interest rate, balance, and term
yearlyBalance PROC
push ebp ; Save base pointer
mov ebp, esp ; Set stack frame
sub esp, 24 ; Allocate space for local variables
; Load parameters from FPU stack
fistp DWORD PTR [ebp-4] ; Store years in local variable
fstp QWORD PTR [ebp-8] ; Store rate in local variable
fstp QWORD PTR [ebp-16] ; Store balance in local variable
mov eax, [ebp-4] ; Load years into eax
mov ecx, eax ; Copy years into ecx for loop counter
; Initialize year counter
mov eax, 1
; Loop for each year
year_loop:
fld QWORD PTR [ebp-16] ; Load balance onto FPU stack
fld QWORD PTR [ebp-8] ; Load rate onto FPU stack
fld1 ; Load 1.0 onto FPU stack
fld st(1) ; Duplicate rate
fdivr st(0), st(2) ; Divide rate by 100(st(0)= rate /100)
fmulp st(1), st(0) ; Multiply balance by rate /100(interest = balance * rate /100)
faddp st(1), st(0) ; Add interest to balance (new balance)
fstp QWORD PTR [ebp-16] ; Store the new balance
; Display the year and balance
push eax ; Save year counter
mov edx, OFFSET yearStr
call writeString
call writeInt
mov edx, OFFSET colonStr
call writeString
mov edx, OFFSET dollarStr
call writeString
fld QWORD PTR [ebp-16] ; Load balance onto FPU stack
call writeFloat
call crlf
pop eax ; Restore year counter
; Increment year counter and loop
inc eax
loop year_loop
mov esp, ebp ; Restore stack
pop ebp ; Restore base pointer
ret
yearlyBalance ENDP
END
(main.asm)
INCLUDE asmlib.inc
; Prototypes for external procedures
yearlyBalance PROTO
.data
promptBalance BYTE "Enter your balance ",0
promptRate BYTE "Enter the interest rate (like 5.0)",0
promptYears BYTE "Enter the number of years ",0
balance REAL8?
rate REAL8?
years DWORD ?
.code
main PROC
; Prompt for and read the balance
mov edx, OFFSET promptBalance
call writeString
call readFloat
fstp balance
; Prompt for and read the interest rate
mov edx, OFFSET promptRate
call writeString
call readFloat
fstp rate
; Prompt for and read the number of years
mov edx, OFFSET promptYears
call writeString
call readInt
mov years, eax
; Load balance, rate, and years onto the FPU stack
fld balance
fld rate
fild years
; Call the yearlyBalance procedure
call yearlyBalance
exit
main ENDP
END main
(THIS IS HOW THE OUTPUT IS SUPPOSED TO LOOK)
The following shows an example output:
Enter your balance
1000
Enter the interest rate (like 5.0)
5.0
Enter the number of years
10
Year: 1: $1050.00
Year: 2: $1102.50
Year: 3 $1157.63
Year: 4: $1215.51
Year: 5: $1276.28
Year: 6: $1340.10
Year: 7: $1407.10
Year: 8: $1477.46
Year: 9: $1551.33
Year: 10: $1628.89
Press any key to continue ...

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!