essay

essay

CSCI 202 Computer Organization II
Instructor: Gedare Bloom
Homework 7 (25 points)
Due: Tuesday, April 5 at 8:00 P.M.
Do this assignment by yourself. Provide detailed calculation and justifications for your numerical answers. Always watch the course website for updates on the assignments.

Answer the following questions supposing the code listing shown starts from main().

.text
fun: # int fun(int s) {
addi $sp, $sp, -8
sw $ra, 0($sp)
sw $a0, 4($sp)
blez $a0, base # if (s > 0) {
addi $a0, $a0, -1 # s--;
jal fun # r = fun(s);
j done # }
base:
addi $v0, $zero, 0 # else r = 0;
done:
lw $ra, 0($sp)
lw $a0, 4($sp)
addi $sp, $sp, 8
add $v0, $v0, $a0 # r = r + s;
jr $ra # return r; }
main: # int main() {
addi $sp, $sp, -8
sw $ra, 0($sp)
sw $s0, 4($sp)
addi $s0, $zero, 0 # x = 0
addi $a0, $zero, 2 # i = 2
loop:
blez $a0, end # while ( i > 0) {
jal fun
add $s0, $s0, $v0 # x = x + fun(i);
addi $a0, $a0, -1 # i--;
j loop # }
end:
addi $v0, $s0, 0
lw $s0, 4($sp)
lw $ra, 0($sp)
addi $sp, $sp, 8
jr $ra # return x; }
Question 1 (10 points)
Machine A uses the single-cycle MIPS processor shown below executing at 500 MhZ.
(a) Describe the necessary changes to the single-cycle processor to add the jal and jr instructions. Be sure to consider datapath and control modifications.

(b) Fill in the table with the number of instructions that are executed and the execution time for the above program with Machine A.
Inst Class
Instructions
TimeA
or, and, slt


add, sub


branch


load


store


jump


Total



Figure 1: Machine A—Single Cycle Processor




Question 2 (10 points)
Machine B uses the 5-stage pipelined MIPS processor shown below executing at 2 GHz.
(a) Describe the changes needed to the pipelined processor to add a hazard detection unit, move branch into ID, and add the j, jal, and jr instructions at ID. There is no forwarding, so hazards stall...

Similar Essays