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

bltz $s0, check_negative_overflow

add $t0, $s0, $v0

blt $t0, $s0, check_positive_overflow

addu $s0, $s0, $v0 # add transaction amount to 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_positive_overflow:

# Print overflow message and skip current transaction

li $v0, 4

la $a0, .overflow_msg

syscall

b loop

check_negative_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 *******************

the code works but the overflow detection works only with negative overflow. I need help with detecting positive overflow that can print the same message and loop.

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 Databases Questions!