I have to make a program that takes a user entered deposit and interest rate and then calculates the balance for 5 years. I can't figure out what I'm doing wrong. I always use the deposit amount of 1000 and interest rate of 5 therefore for the five years the balance should be
- 1050
- 1102
- 1157
- 1214
- 1274
I don't get this I get
- 6000
- 36000
- 216000
- 1296000
its not even 5 years and the values are wrong. Any help is greatly appreciated. Here is my code.
#Program to:
#Calculate the new balance after each year for a deposit and
#an interest rate entered by the user for five years.
.data #variable used follow this line
promptDeposit: .asciiz "Enter the deposit amount:"
promptRate: .asciiz "Enter the interest rate in percent form:"
promptBB: .asciiz "Beginning Balance:"
promptD: .asciiz "Deposit:"
promptIR: .asciiz "Interest rate:"
promptNL: .asciiz "\n"
.text #program's code after this line
main:
li $v0, 4 # System call code for print string
la $a0, promptDeposit # Load address of the promptDeposit string
syscall # call OS to Print promptDeposit
li $v0, 5 # System call code for read integer
syscall # call OS to Read integer into $v0
move $s0, $v0 # Move the integer into $s0
li $v0, 4 # System call code for print string
la $a0, promptRate # Load address of the promptRate string
syscall # call OS to Print promptRate
li $v0, 5 # System call code for read integer
syscall # call OS to Read integer into $v0
move $s1, $v0 # Move the integer into $s1
li $v0, 4
la $a0, promptD
syscall
move $a0, $s0
li $v0, 1
syscall
li $v0, 4
la $a0, promptNL
syscall
li $v0, 4
la $a0, promptIR
syscall
move $a0, $s1
li $v0, 1
syscall
li $v0, 4
la $a0, promptNL
syscall
jal CompBal
#Exits Program
li $v0, 10 #System call code to Exit
syscall #call OS to Exit the program
CompBal:
sw $ra, ($sp)
li $v0, 4
la $a0, promptBB
syscall
move $a0, $s0
li $v0, 1
syscall
li $v0, 4
la $a0, promptNL
syscall
li $t0, 0
li $t1, 4
li $t3, 100
div $s1, $t3
mfhi $s1
loop:
mult $s0, $s1
mflo $t2
add $s0, $t2, $s0
addi $t0, $t0, 1
move $a0, $s0
li $v0, 1
syscall
li $v0, 4
la $a0, promptNL
syscall
bne $t0, $t1, loop
end:
jr $ra