Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[URGENT] I REALLY NEED HELP NOW WITH THIS ASSIGNMENT IN MARS MIPS SIMULATOR! I HAVE UPLOAD THE QUESTIONS AND THE HINT I GOT FOR THIS.

[URGENT] I REALLY NEED HELP NOW WITH THIS ASSIGNMENT IN MARS MIPS SIMULATOR!

I HAVE UPLOAD THE QUESTIONS AND THE HINT I GOT FOR THIS. PLEASE HELP ME OUT!

image text in transcribed

**BELOW IS THE HINT FOR THIS BUT I DO NOT UNDERSTAND HOW TO DO IT**

image text in transcribed

image text in transcribed

**BELOW IS THE CODE NEED TO BE MODIFIED**

image text in transcribed

image text in transcribed

##################################################################### # Programmer: # Course: CSC 303-D1 ##################################################################### # Functional Description: # This program can be used to balance your check book. # ##################################################################### # Pseudocode: # Print Header; # s0 = 0; # loop: Prompt user for transaction; # v0 # cout ###################################################################### .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

**THIS IS VERY URGENT** PLEASE HELP ME OUT! THANK YOU IN ADVANCE

Attached you will find a MIPS assembly language program that could be used to balance your checkbook (Coding Assignment1_Need ToModify.s). Negative transaction values correspond to checks drawn on the checking account and positive transactions values correspond to deposits into the checking account. The program terminates when a value of zero is read in. After each transaction the new calculated balance is displayed. Run this program. Use the single step feature to observe the contents of the registers as the program executes. Set a few breakpoints in the program and observe the results. Notice that this program only works for integer values. The program includes a heading with a place to insert your name. The program also includes to-do items like pseudo code explanation of newly added code with at different places within the code. This program provides an example of how all of your programs should be documented in this course. The "syscall instructions are calls to system services to perform input output functions. Run this program and input two deposits in the amount of 1234567890. You will notice that this program does not contain any instructions to detect when overflow occurs so it produces an erroneous balance when overflow does occur. Your job for this programming assignment is to make improvements to this program so that whenever an overflow does occur in either the positive or negative domain the following specific announcement will be displayed: "Overflow Occurred - Transaction Ignored" Next the correct previous balance should be displayed on the following line in the Balance column. Then the program should prompt the user for the next transaction. No message other than the one specified above is acceptable! Be sure to place in-line comments within the program everywhere you have made changes to the initial program. Each of your comments should be preceded by #### to make it easy to find your modifications to the initial program. The grading rubric is as follows - Comments and style = 2 points Program improvement - 1. Detects overflow = 3 points 2. Prints announcement of overflow = 2 points 3. Displays correct previous balance = 3 points The assignment asks you to detect when overflow occurs (adding new transaction to bank balance results in an erroneous value for balance) and to print a message saying that it occurred, while keeping the bank balance unmodified i.e. the balance before the current transaction. E.g. in the beginning with balance 0 when user deposits 1234567890, it shows correct balance but in the second transaction if user deposits 1234567890 again, the balance shown is erroneous since overflow has occurred. Discussion of overflow How to detect overflow? No overflow when adding a +ve and a -ve number No overflow when signs are the same for subtraction Overflow occurs when the value affects the sign: o Overflow when adding two +ves yields a -ve o Or, adding two-ves gives a +ve o Or, subtract a -ve from a +ve and get a -ve o Or, subtract a +ve from a -ve and get a +ve Review of 2's complement number system: to know what the numbers are in decimal, apply the two step method for -ve numbers (for +ve numbers you just do the regular thing, which is multiply digits with place values and add all of them) - 1. Invert the bits 2. Add one That gives the +ve version of the number Example using a 4-bit number 1100 -> inverting bits gives 0011 -> adding 1 gives 0100 -> this is 4 in decimal, so the put the -ve sign in front and that tells us 1100 is -4. In this example there is no overflow. The 4 bits of the answer (note that the bit that shows up on the extreme left is discarded since the answer must also be written in 4 bits), is correct as seen by the conditions stated above since adding two-ves has given a -ve. 1100 #-4 +1110 #-2 11010 #-6 in 4 bits, and -2 + (-4)= -6 so that's correct. In the next example there is overflow. The 4 bits of the answer is not correct as seen by the conditions stated above since adding two-ves has given a +ve (in the 4 bit result). 1100 #-4 +1010 #-6 10110 # +6 in the 4 bits result, so that's not correct! Developing the overflow detection in the given MIPS program There are several ways of doing this, let's discuss one way. Line 52 of the given code is where the current transaction input is being added to the existing balance so it makes sense to add code before this line (but after line 52 since that line checks if input is 0) to test for overflow. This is the first algorithm sketch with mix of pseudo-code and assembly which should go in- between lines 51 and 52, with introduction of three different labels - # NEED OVERFLOW DETECTION CODE HERE overflow: system call to print error message string j print_balance not_overflow: addu $s0, $50, $v0 print balance: ... # this code is provided Expanding the first sketch to fill in OVERFLOW DETECTION CODE - put balance + transaction in a temporary register if (balance is -ve) and (transaction is -ve) and (temp register is +ve) j overflow if (balance is +ve) and (transaction is +ve) and (temp register is -ve) j overflow j not overflow # since previous conditions are not true of this is reached overflow: system call to print error message string j print balance not_overflow: addu $s0, $80, $v0 print_balance: - # this code is provided Remaining tasks (noting that the register $50 is used to store balance and $v0 has the transaction input) are to write down in MIPS assembly the pseudo if statements, print message and choose a temporary register ... 2 3 # Programmer: # Course: CSC 303-01 6 7 # Functional Description: # This program can be used to balance your check book. # # # # 9 # Pseudocode: 10 # Print Header; s0 = 0; 12 # Loop: Prompt user for transaction; VO 17 # cout 28 29 Head: 30 .data # Data declaration section .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" .asciiz "\t\t\t\t\t\t\t\t\t" .asciiz " Transaction:" asciiz " **** Adios Amigo **** " 32 tabs: 33 tran: 34 bye: .text # Executable code follows main: li la $v0, 4 $a), Head # system call code for print_string # load address of Header message into $a) # print the Header syscall move $50, $zero # Set Bank Balance to zero loop: li $v0, 4 $a0, tran la # system call code for print_string # Load address of prompt into sa # print the prompt message syscall 47 48 li $v0, 5 # system call code for read integer # reads the amount of Transaction into $v0 49 syscall 50 51 52 beqz addu $v0, done $50, $50, $v0 # If $v0 equals zero, branch to done # add transaction amount to the Balance 53 54 55 li la syscall $v0, 4 $a0, tabs # system call code for print_string # load address of tabs into $a0 # used to space over to the Balance column 56 57 58 li 59 60 $v0, 1 move $20, $50 syscall loop # system call code for print_integer # move Bank Balance value to $a0 # print Bank Balance # branch to loop 61 62 63 done: 64 $v0, 4 la $a0, bye syscall # system call code for print string # load address of msg. into $a0 # print the string 65 66 67 li $v0, 10 syscall # terminate program run and # return control to system 68 69 70 # END OF PROGRAM 71 Attached you will find a MIPS assembly language program that could be used to balance your checkbook (Coding Assignment1_Need ToModify.s). Negative transaction values correspond to checks drawn on the checking account and positive transactions values correspond to deposits into the checking account. The program terminates when a value of zero is read in. After each transaction the new calculated balance is displayed. Run this program. Use the single step feature to observe the contents of the registers as the program executes. Set a few breakpoints in the program and observe the results. Notice that this program only works for integer values. The program includes a heading with a place to insert your name. The program also includes to-do items like pseudo code explanation of newly added code with at different places within the code. This program provides an example of how all of your programs should be documented in this course. The "syscall instructions are calls to system services to perform input output functions. Run this program and input two deposits in the amount of 1234567890. You will notice that this program does not contain any instructions to detect when overflow occurs so it produces an erroneous balance when overflow does occur. Your job for this programming assignment is to make improvements to this program so that whenever an overflow does occur in either the positive or negative domain the following specific announcement will be displayed: "Overflow Occurred - Transaction Ignored" Next the correct previous balance should be displayed on the following line in the Balance column. Then the program should prompt the user for the next transaction. No message other than the one specified above is acceptable! Be sure to place in-line comments within the program everywhere you have made changes to the initial program. Each of your comments should be preceded by #### to make it easy to find your modifications to the initial program. The grading rubric is as follows - Comments and style = 2 points Program improvement - 1. Detects overflow = 3 points 2. Prints announcement of overflow = 2 points 3. Displays correct previous balance = 3 points The assignment asks you to detect when overflow occurs (adding new transaction to bank balance results in an erroneous value for balance) and to print a message saying that it occurred, while keeping the bank balance unmodified i.e. the balance before the current transaction. E.g. in the beginning with balance 0 when user deposits 1234567890, it shows correct balance but in the second transaction if user deposits 1234567890 again, the balance shown is erroneous since overflow has occurred. Discussion of overflow How to detect overflow? No overflow when adding a +ve and a -ve number No overflow when signs are the same for subtraction Overflow occurs when the value affects the sign: o Overflow when adding two +ves yields a -ve o Or, adding two-ves gives a +ve o Or, subtract a -ve from a +ve and get a -ve o Or, subtract a +ve from a -ve and get a +ve Review of 2's complement number system: to know what the numbers are in decimal, apply the two step method for -ve numbers (for +ve numbers you just do the regular thing, which is multiply digits with place values and add all of them) - 1. Invert the bits 2. Add one That gives the +ve version of the number Example using a 4-bit number 1100 -> inverting bits gives 0011 -> adding 1 gives 0100 -> this is 4 in decimal, so the put the -ve sign in front and that tells us 1100 is -4. In this example there is no overflow. The 4 bits of the answer (note that the bit that shows up on the extreme left is discarded since the answer must also be written in 4 bits), is correct as seen by the conditions stated above since adding two-ves has given a -ve. 1100 #-4 +1110 #-2 11010 #-6 in 4 bits, and -2 + (-4)= -6 so that's correct. In the next example there is overflow. The 4 bits of the answer is not correct as seen by the conditions stated above since adding two-ves has given a +ve (in the 4 bit result). 1100 #-4 +1010 #-6 10110 # +6 in the 4 bits result, so that's not correct! Developing the overflow detection in the given MIPS program There are several ways of doing this, let's discuss one way. Line 52 of the given code is where the current transaction input is being added to the existing balance so it makes sense to add code before this line (but after line 52 since that line checks if input is 0) to test for overflow. This is the first algorithm sketch with mix of pseudo-code and assembly which should go in- between lines 51 and 52, with introduction of three different labels - # NEED OVERFLOW DETECTION CODE HERE overflow: system call to print error message string j print_balance not_overflow: addu $s0, $50, $v0 print balance: ... # this code is provided Expanding the first sketch to fill in OVERFLOW DETECTION CODE - put balance + transaction in a temporary register if (balance is -ve) and (transaction is -ve) and (temp register is +ve) j overflow if (balance is +ve) and (transaction is +ve) and (temp register is -ve) j overflow j not overflow # since previous conditions are not true of this is reached overflow: system call to print error message string j print balance not_overflow: addu $s0, $80, $v0 print_balance: - # this code is provided Remaining tasks (noting that the register $50 is used to store balance and $v0 has the transaction input) are to write down in MIPS assembly the pseudo if statements, print message and choose a temporary register ... 2 3 # Programmer: # Course: CSC 303-01 6 7 # Functional Description: # This program can be used to balance your check book. # # # # 9 # Pseudocode: 10 # Print Header; s0 = 0; 12 # Loop: Prompt user for transaction; VO 17 # cout 28 29 Head: 30 .data # Data declaration section .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" .asciiz "\t\t\t\t\t\t\t\t\t" .asciiz " Transaction:" asciiz " **** Adios Amigo **** " 32 tabs: 33 tran: 34 bye: .text # Executable code follows main: li la $v0, 4 $a), Head # system call code for print_string # load address of Header message into $a) # print the Header syscall move $50, $zero # Set Bank Balance to zero loop: li $v0, 4 $a0, tran la # system call code for print_string # Load address of prompt into sa # print the prompt message syscall 47 48 li $v0, 5 # system call code for read integer # reads the amount of Transaction into $v0 49 syscall 50 51 52 beqz addu $v0, done $50, $50, $v0 # If $v0 equals zero, branch to done # add transaction amount to the Balance 53 54 55 li la syscall $v0, 4 $a0, tabs # system call code for print_string # load address of tabs into $a0 # used to space over to the Balance column 56 57 58 li 59 60 $v0, 1 move $20, $50 syscall loop # system call code for print_integer # move Bank Balance value to $a0 # print Bank Balance # branch to loop 61 62 63 done: 64 $v0, 4 la $a0, bye syscall # system call code for print string # load address of msg. into $a0 # print the string 65 66 67 li $v0, 10 syscall # terminate program run and # return control to system 68 69 70 # END OF PROGRAM 71

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions