2) Compiling andAssembling by Hand (a) The MIPS translation of the Csegment whil
ID: 3613402 • Letter: 2
Question
2) Compiling andAssembling by Hand
(a)The MIPS translation of the Csegment
while (save[i] == k)
i += 1;
uses both a conditional branch and anunconditional jump each time
through the loop. Only poor compilers wouldproduce code with this loop overhead.
Rewrite the assembly code so that it uses atmost one branch or jump each time through
the loop. How many instructions are executedbefore and after the optimization if the
number of iterations of the loop is 10(i.e., save[i + 10] does notequal k and
save[i], ..., save[i + 9] equals k)?
(b)Using the following MIPS program, determine theinstruction format for each instruction
and the decimal values of each instructionfield.
addi $v0, $zero, 0
loop: lw $v1, 0($a0)
sw $v1, 0($a1)
addi $a0, $a0, 4
addi $a1, $a1, 4
beq $v1, $zero, loop
Explanation / Answer
How many instructions are executed beforeand after the optimization if the
number of iterations of the loop is 10(i.e., save[i + 10] does notequal k and
save[i], ..., save[i + 9] equals k)? 33 optimized 42 notoptimized (not 100%)
(b)Using the following MIPS program, determine the instructionformat for each instruction
and the decimal values of each instructionfield.
address instruction
addi $v0, $zero,0 immediate 0 001000 00000 000100000000000000000
loop: lw $v1,0($a0) 4 100011 00100 000110000000000000000
sw $v1,0($a1) 8 101011 00101 000110000000000000000
addi $a0, $a0,4 immediate C 001000 0010000100 0000000000000100
addi $a1, $a1,4 immediate 10 001000 00101 001010000000000000100
beq $v1, $zero, loop immediate 14 000100 00011 000000000000000000100
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.