Question: ##################################################################### # Functional Description: # This program can be used to balance your checkbook. # This program has been modified to detect overflow and display

#####################################################################

# Functional Description:

# This program can be used to balance your checkbook.

# 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 three different experts but seems like their codes did not make it through my QtSpim.

The code above is from the second expert and the code below is from the first expert.

The first expert was not able to handle the positive flow and the second expert code which is above just cannot take any values and will print out the string "An overflow had occurred" no matter what value I input.

Please help me with this question. The last expert did not even put an answer that related to my question.

**********************

#####################################################################

# Functional Description:

# This program can be used to balance your check book.

#

#####################################################################

# Pseudocode:

# Print Header;

# s0 = 0;

# loop: Prompt user for transaction;

# v0 << transaction amount;

# if (v0 = 0) done;

# 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 **** "

.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

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

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 OF PROGRAM

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!