Student Loan Program. Prompt for 1) an initial loan amount, 2) the annual percen
ID: 3631215 • Letter: S
Question
Student Loan Program.Prompt for
1) an initial loan amount,
2) the annual percentage rate, and
3) the desired monthly payments. Print out a repayment schedule with at least 4 columns: the month, month’s beginning balance, current months interest, and total paid.
Add text column headings at the top of the chart. Output the correct last payment amount and the total interest paid. (The special character ‘ ’, tab, can be used to align output columns)
current_months_interest = (beginning_balance * annual_percentage_rate) / ( 12 * 100)
beginning_balance = beginning_balance - ( payment – current_months_interest)
This problem should use integer arithmetic, not floating point. There are three levels of this program.
1) Basic (max score=90):
a) Integer arithmetic and whole dollar amounts.
b) Results displayed in whole dollars
2) Intermediate (max score=95):
a) Integer arithmetic and dollar amounts in cents.
b) Displayed in whole dollars
3) Advanced (max score=100):
a) Same as intermediate, but
b) results displayed in dollars and cents format
Explanation / Answer
.data
getprin: .asciiz " Enter initial loan principal: "
getapr: .asciiz " Enter annual percentage rate (APR): "
getpay: .asciiz " Enter desired monthly payment: "
head1: .asciiz " Month Balance Int. Pd. Total Pd."
head2: .asciiz " ----- ------- -------- ---------"
complete: .asciiz " Completed - last payment is $"
tab: .asciiz " "
newline: .asciiz " "
nogo: .asciiz " Monthly payment too low to amortize loan; please reenter."
################################################################
# TEXT SEGMENT #
################################################################
.text
.globl main
main:
getdata:
# GET PRINCIPAL ---------------------------------------------------
li $v0, 4 # print_str syscall
la $a0, getprin # address for string
syscall
li $v0, 5 # read_int syscall
syscall
move $t0, $v0 # $s0 = PRINCIPAL
# GET APR ---------------------------------------------------------
li $v0, 4 # print_str syscall
la $a0, getapr # address for string
syscall
li $v0, 5 # read_int syscall
syscall
move $t1, $v0 # $s1 = APR
# GET MONTHLY PAYMENT----------------------------------------------
li $v0, 4 # print_str syscall
la $a0, getpay # address for string
syscall
li $v0, 5 # read_int syscall
syscall
move $t2, $v0 # $s2 = PAYMENT
# ERROR CHECK - MAKE SURE VALUES WILL AMORTIZE -------------------
li $t3, 1200 # load 1200 in $t0
divu $t4, $t1, $t3 # $t4 = APR / 1200
move $t1, $t4
mult $t1, $t0 # (APR/1200) * Principal
mflo $t7 # $t1 = (line above)
bge $t2, $t7, calc # branch to calc if monthly
# payment is big enough to amortize
li $v0, 4 # print_str syscall
la $a0, nogo # address for string
syscall
j getdata # jump back to getdata
calc:
# PRINT HEADER ---------------------------------------------------------
li $v0, 4
la $a0, head1
syscall
li $v0, 4
la $a0, head2
syscall
li $t3, 0
li $t4, 0
li $t5, 0
li $t6, 0
# $t0 = principal or balance
# $t1 = APR/1200 = MPR
# $t2 = monthly payment
# $t3 = payment # or month
# $t4 = current interest paid
# $t5 = total interest paid
# $t6 = total amount paid
loopstart:
# CALCULATIONS ------------------------------------------------------------
addi $t3, $t3, 1 # increment payment # or month
mult $t1, $t0 # current int pd = mpr * principal
mflo $t4
add $t5, $t5, $t4 # total int += current int
add $t6, $t6, $t2 # total paid += monthly payment
# PRINT NEWLINE -----------------------------------------------------------
li $v0, 4 # print_str syscall
la $a0, newline # address for string
syscall
# PRINT MONTH or PAYMENT NUM ----------------------------------------------
li $v0, 1 # system call code for print_int
move $a0, $t3 # integer to print
syscall # print it
move $t3, $a0 # move counter back to $t0
# PRINT TAB ---------------------------------------------------------------
li $v0, 4 # print_str syscall
la $a0, tab # address for string
syscall
# PRINT BALANCE -----------------------------------------------------------
li $v0, 1 # system call code for print_int
move $a0, $t0 # integer to print
syscall # print it
move $t0, $a0 # move balance back to $s0
# PRINT TAB (x2) ----------------------------------------------------------
li $v0, 4 # print_str syscall
la $a0, tab # address for string
syscall
li $v0, 4 # print_str syscall
la $a0, tab # address for string
syscall
# PRINT INTEREST PAID -----------------------------------------------------
li $v0, 1 # system call code for print_int
move $a0, $t5 # integer to print
syscall # print it
move $t5, $a0 # move tot. int. back to $t2
# PRINT TAB (x2) ----------------------------------------------------------
li $v0, 4 # print_str syscall
la $a0, tab # address for string
syscall
li $v0, 4 # print_str syscall
la $a0, tab # address for string
syscall
# PRINT TOTAL AMOUNT PAID -------------------------------------------------
li $v0, 1 # system call code for print_int
move $a0, $t6 # integer to print
syscall # print it
move $t6, $a0 # move balance back to $s0
# -------------------------------------------------------------------------
sub $t0, $t0, $t2 # calculate new balance
add $t0, $t0, $t4 # balance - payment + current int.
# END LOOP ----------------------------------------------------------------
bgt $t0, $t2, loopstart # if balance > monthly payment repeat loop
addi $t3, $t3, 1 # increment payment # or month
mult $t1, $t0 # current int pd = mpr * principal
mflo $t4
add $t0, $t0, $t4 # calculates last payment
# = balance + current interest
# PRINT NEWLINE -----------------------------------------------------------
li $v0, 4 # print_str syscall
la $a0, newline # address for string
syscall
# PRINT FINAL PAYMENT -----------------------------------------------------
li $v0, 4
la $a0, complete
syscall
li $v0, 1 # system call code for print_int
move $a0, $t0 # integer to print
syscall # print it
# END -------------------------------------------------------------------
li $v0, 10 # return to kernel from main routine
syscall