Question: Problem 1 : Write a function add 6 4 that adds two input unsigned 6 4 bit integers x and y and returns the unsigned

Problem 1: Write a function add64 that adds two input unsigned 64 bit integers x and y and returns the unsigned 64 bit integer sum z, i.e. z = x + y. In your main function, you should assume that x, y, and z will be stored in the following 6 registers as follows:
x: upper 32 bits in $t1 lower 32 bits in $t0
y: upper 32 bits in $t3 lower 32 bits in $t2
z: upper 32 bits in $t5 lower 32 bits in $t4
Your main function call should read the values of x and y into the stack, invoke add64, and then return z on the stack.
Also, your function should generate an error only if there is an overflow in the overall 64 bit addition (and not if there is an overflow in the addition of the lower 32 bit components).
Problem 2:
Consider the following loop that takes calculates the sum of two arrays:
.data
arr1: .word 12345678910111213141516
arr2: .word 12345678910111213141516
arr_sum: .space 64 # equal to 16 words
.text
la $a0, arr1
la $a1, arr2
la $a2, arr_sum
li $s0,16 # loop counter
loop:
beqz $t0, done
lw $t0, arr1
lw $t1, arr2
add $t2, $t0, $t1
sw $t2, arr_sum
addi $s0, $s0,-1
addi $a0, $a0,4
addi $a1, $a1,4
addi $a2, $a2,4
b loop
done:
A. Calculate the total number of clock cycles needed to run this program if the CPU does not use any pipelines. For simplicity, you may assume that each instruction in the above program is atomic and not a macro that can expand into multiple instructions (such as li and la). What is the CPI?
B. Calculate the total number of clock cycles needed to run this program if the CPU uses pipelining and automatically inserts nop instructions where needed to avoid data hazards. You may also assume perfect branch prediction, i.e., there are no wasted clock cycles due to control hazards (so you don't have to insert nop instructions due to beqz instruction).

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