Consider the following C-code fragment: for (i=0; i<100; i++) a[i] = b[i] - d[i]
ID: 3885877 • Letter: C
Question
Consider the following C-code fragment: for (i=0; i<100; i++) a[i] = b[i] - d[i];
Assume that - a, b, and d are arrays of 32-bit words, - The machine code for this fragment is stored in memory starting from location 00000100 Hex.
a- Convert this code to MIPS. You must provide the numeric offset for each branch or jump instruction that you use. (20 points)
b- Assume that the CPIs for MIPS instructions are as listed below: a. lw : 5 cycles b. R-type, addi, sw, and other immediate Arithmetic instruction : 4 Cycles c. beq, bne, and j: 3 cycles How many clock cycles does it take to execute the C-code fragment? (15 points)
c- Assume that this code is executed by a 1.6 GHz system. What is the cpu execution time for the code? (10 points)
Explanation / Answer
Address Data
12 1
8 6
4 4
0 2
b. Address Data
16 1
12 2
8 3
4 4
0 5add $s1,$s2,$s3 $s1 = $s2 + $s3
sub $s1,$s2,$s3 $s1 = $s2 – $s3
addi $s1,$s2,4 $s1 = $s2 + 4
ori $s1,$s2,4 $s2 = $s2 | 4
lw $s1,100($s2) $s1 = Memory[$s2+100]
sw $s1,100($s2) Memory[$s2+100] = $s1
bne $s4,$s5,Label Next instr. is at Label if $s4 ¹ $s5
beq $s4,$s5,Label Next instr. is at Label if $s4 = $s5
slt $t1,$s2,$s3 if $s2 < $s3, $t1 = 1 else $t1 = 0
j Label Next instr. is at Label
jr $s1 Next instr is in register $s1
jal Label Jump and link procedure at Label
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.