Question: ##################################################################### # Functional Description: # This program can be used to balance your check book. # This program has been modified to detect overflow and
#####################################################################
# Functional Description:
# This program can be used to balance your check book.
# This program has been modified to detect overflow and display a message when it occurs.
#####################################################################
# Pseudocode:
# Print Header;
# s0 = 0;
# loop: Prompt user for transaction;
# v0 << transaction amount;
# if (v0 = 0) done;
# check for overflow in positive and negative domains
# if overflow occurs, print message and skip current transaction
# s0 = s0 + v0;
# cout << s0
# go to loop
# done:
# cout << "Adios Amigo"
#
######################################################################
# Register Usage:
# $v0: Transaction Amount
# $s0: Current Bank Balance
#
######################################################################
.data # Data declaration section
Head: .ascii " \tThis program, written by
.ascii " can be used to balance your check book."
.asciiz " \t\t\t\t\t\t\t\t\t Balance"
tabs: .asciiz "\t\t\t\t\t\t\t\t\t"
tran: .asciiz " Transaction:"
bye: .asciiz " **** Adios Amigo **** "
.overflow_msg: .asciiz " An Overflow had Occurred - This transaction has been ignored."
.text # Executable code follows
main:
li $v0, 4 # system call code for print_string
la $a0, Head # load address of Header message into $a0
syscall # print the Header
move $s0, $zero # Set Bank Balance to zero
loop:
li $v0, 4 # system call code for print_string
la $a0, tran # load address of prompt into $a0
syscall # print the prompt message
li $v0, 5 # system call code for read_integer
syscall # reads the amount of Transaction into $v0
beqz $v0, done # If $v0 equals zero, branch to done
# Check for overflow in positive and negative domains
# If overflow occurs, print message and skip current transaction
# Check for negative overflow
bltz $s0, check_overflow
# Check for positive overflow
add $t0, $s0, $v0
bgt $t0, 2147483647, check_overflow
# If there is no overflow, add the transaction amount to the balance
addu $s0, $s0, $v0
# Print the balance
li $v0, 4 # system call code for print_string
la $a0, tabs # load address of tabs into $a0
syscall # used to space over to the Balance column
li $v0, 1 # system call code for print_integer
move $a0, $s0 # move Bank Balance value to $a0
syscall # print Bank Balance
b loop # branch to loop
check_overflow:
# Print overflow message and skip current transaction
li $v0, 4
la $a0, .overflow_msg
syscall
b loop
done: li $v0, 4 # system call code for print_string
la $a0, bye # load address of msg. into $a0
syscall # print the string
li $v0, 10 # terminate program run and
syscall # return control to system
# END
*************** I have asked two different experts but seems like their code did not make it through my QtSpim The above code gives me the message "An Overflow had Occured - ...." No matter what the value. I am stuck here. Thanks in advance.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
