Question

In: Computer Science

2. Single step the instructions.s program through at least two exceptions. Make sure that you see...

2. Single step the instructions.s program through at least two exceptions. Make sure that you see how the flow of control is changed by comparing the source code with PCSpim windows, pay particular attention to all registers.

Question 2 (0.4): how do you recognise that the normal program flow has been interrupted?

Question 3 (0.5): how can you find out what exception condition has occurred and what caused it?

#--------------------instruction.s---------------------
# This program implements:
#       sum = 0;
#       i = 9;
#       do {
#               sum = sum + A[9-i]
#               B[9-i] = sum;
#               i--;
#       }
#       until (i = 0) 


                .globl main     
main:
                add     $t2, $0, $0     # sum = 0  (sum is in $t2)
                add     $t1, $0, $0     # Set $t1 to point to beginning of data
                lw      $t4, 84($t1)    # Constant 4 stored in $t4
                lw      $t0, 88($t1)    # Constant 9 stored in $t0 (i)
                lw      $t5, 92($t1)    # Constant -1 stored in $t5
                add     $t1, $t1,$t4    # A starts at 4 (move $t1 to point to A)
loop:
                lw      $t3, 0($t1)     # $t3 has A[k]
                add     $t2, $t2, $t3   # sum = sum + A[k]
                sw      $t2, 40($t1)    # B[k] = sum
                add     $t1, $t1, $t4   # update address pointer
                add     $t0, $t0, $t5   # i--
                beq     $t0, $0, done   # if i = 0 go to done
                j       loop            # if i > 0 go to loop
done:   
                add     $t1, $0, $0     # Set $t1 to point to beginning of data
                sw      $t2, 0($t1)     # sum is stored
                li      $v0, 4          # print_str
                la      $a0, message    # load address of string 
                syscall                 #
                li      $v0, 1          # print_int
                lw      $a0, sum        # load integer value
                syscall                 #
                jr      $ra             # return to the main program
                add     $0, $0, $0      # nop


                .data
sum:            .word   0
A:              .word   0, 1, 2, 3, 4, 5, 6, 7, 8, 9
B:              .word   0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Four:           .word   4
Nine:           .word   9
Minus1:         .word   -1
message:        .asciiz "\nThe value of sum is:  

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

Here error was due to following line of code.

1. due to line where it is mentioned t# Set $t1 to point to beginning of data

becuase the starting address of data is 0x10010000. It was initiated with 0

2. same error at another place whre t1 initialized to beginning of data.

3. " was missing in message data .

message:        .asciiz "\nThe value of sum is:  

Updated code is as below.

.globl main   
.text
main:
add $t2, $0, $0 # sum = 0 (sum is in $t2)
add $t1,$0,0x10010000 # Set $t1 to point to beginning of data
lw $t4, 84($t1) # Constant 4 stored in $t4
lw $t0, 88($t1) # Constant 9 stored in $t0 (i)
lw $t5, 92($t1) # Constant -1 stored in $t5
add $t1, $t1,$t4 # A starts at 4 (move $t1 to point to A)
loop:
lw $t3, 0($t1) # $t3 has A[k]
add $t2, $t2, $t3 # sum = sum + A[k]
sw $t2, 40($t1) # B[k] = sum
add $t1, $t1, $t4 # update address pointer
add $t0, $t0, $t5 # i--
beq $t0, $0, done # if i = 0 go to done
j loop # if i > 0 go to loop
done:   
add $t1,$0,0x10010000 # Set $t1 to point to beginning of data
sw $t2, 0($t1) # sum is stored
li $v0, 4 # print_str
la $a0, message # load address of string
syscall #
li $v0, 1 # print_int
lw $a0, sum # load integer value
syscall #
jr $ra # return to the main program
add $0, $0, $0 # nop


.data
sum: .word 0
A: .word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
B: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Four: .word 4
Nine: .word 9
Minus1: .word -1
message: .asciiz "\nThe value of sum is: "

2.)

On executing default code follwoing error was there.

3)

By seeing the error it is noticible that the program is trying to accesss non exist element in memroy. And it was causing the exception.


Related Solutions

What you see as the challenges of globalization. Make sure that you mentioned at least three...
What you see as the challenges of globalization. Make sure that you mentioned at least three challenges and pick one of those challenges to go further in depth. Mention an organization that struggled within their globalization strategy and explain exactly why they failed. Additionally, you need to explain why the cultural, legal, political and economic systems will be different from one part of the world compared to another part of the world. When explaining this it is imperative to show...
Write a Java Program using the concept of objects and classes. Make sure you have two...
Write a Java Program using the concept of objects and classes. Make sure you have two files Employee.java and EmployeeRunner.java. Use the template below for ease. (Please provide detailed explanation) Class Employee Class Variables: Name Work hour per week Hourly payment Class Methods: - Get/Sets - generateAnnualSalary(int:Duration of employment)               annual salary = Hourly payment * Work hours per week * 50 If the employee is working for more than 5 years, 10% added bonus             -void displayAnnualSalary ( )...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate from your class BetterRectangle. Lastly, post a picture of your code inside an IDE along with your output. My code is below, needs modification. E9.13The java.awt.Rectangle class of the standard Java library does not supply a method to compute the area or perimeter of a rectangle. Provide a subclass BetterRectangle ofthe Rectangle class that has getPerimeter and getArea methods. Do not add any instance...
Conduct a brief SWOT for the UML undergraduate program.  Be sure to include at least two factorsrepresenting...
Conduct a brief SWOT for the UML undergraduate program.  Be sure to include at least two factorsrepresenting each of the four major sections of a SWOT analysis, and be sure to label each factor to indicate which of those four sections it belongs in.
Analyze the effect of the following events on the economy. Make sure to explain everything step-by-step....
Analyze the effect of the following events on the economy. Make sure to explain everything step-by-step. The example is provided in the first task. a) The central bank increases the money supply. Ms increases => interest rate decreases => investment increases =>Y increases On the graph: LM shifts to the right; at the new equilibrium point, Y increases, interest rate decreases. b) The government increases taxes. c) The government increases government spending. d) MPC increases. e) the tax rate decreases.
Problem 5 This problem is designed to make sure you can write a program that swaps...
Problem 5 This problem is designed to make sure you can write a program that swaps data passed into it such that the caller's data has been swapped. This is something that is done very frequently in manipulating Data Structures. The Solution / Test Requirements I want your program to demonstrate that you understand how to swap information passed into a function and have the calling routine print out the data before and after the call to verify the data...
Part D When solving problems involving stoichiometric coefficients, the first step is to make sure you...
Part D When solving problems involving stoichiometric coefficients, the first step is to make sure you have a balanced chemical equation. Then, you determine the limiting reagent by using the coefficients from the balanced equation. You can keep track of the amounts of all reactant and products before and after a reaction using an ICF table. Completing the ICF table will also allow you to determine the limiting reagent, and the amount of product formed assumes that the reaction runs...
Insert at least three rows of data to each table. Make sure you keep the primary...
Insert at least three rows of data to each table. Make sure you keep the primary key and foreign key constraints. Tables: Cust Table: cid, -- customer id cname, --- customer name cphone, --- customer phone cemail, --- customer email Category table: ctid, --- category id ctname, --- category name parent, --- parent category id since category has a hierarchy structure, power washers, electric power washers, gas power washers. You can assume that there are only two levels. Tool: tid,...
Make sure you understand the two alternatives. The "make" means that KCSB assembles and ships all...
Make sure you understand the two alternatives. The "make" means that KCSB assembles and ships all of its regular bicycles. The "buy" means that KCSB pays another firm to assemble and ship some of its regular bicycles and uses the freed-up resources to make and sell specialty racing bicycles. TIP: The analysis can be simplified by ignoring all irrelevant tiems - the revenue and the costs for the bicycles that are not being outsourced. Instead, just focus on 1) the...
Make sure you understand the two alternatives. The "make" means that KCSB makes, assembles, and ships...
Make sure you understand the two alternatives. The "make" means that KCSB makes, assembles, and ships all of its bicycles. The "buy" means that KCSB makes, assembles, and ships some of its bicycles, makes some of its bicycles and pays another firm to assemble and ship them, and uses idle resources to make and sell specialty racing bicycles ______________________________________________________ King City Specialty Bikes (KCSB) produces high-end bicycles. Costs to manufacture and market the bicycles at last year's volume level of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT