Consider the following MIPS assembly program executing on a pipelined datapath w
ID: 3907062 • Letter: C
Question
Consider the following MIPS assembly program executing on a pipelined datapath with no hardware for hazard handling. Assume a branch penalty of 2 cycles.
Loop: add
sub $4, $5, $1
or $5, $6, $7
and $8, $9, $10
slt $11, $12, $5
beq $13, $14, Loop
add $15, $16, $17
a) Add as few NOPs as possible to this instruction sequence to ensure that hazards are eliminated and the code executes correctly. Do not reorder any instructions.
b) Now reorder the instructions to eliminate as many NOPs as possible without affecting the correctness of execution.
Explanation / Answer
With nop
Loop: add
sub $4, $5, $1
nop
or $5, $6, $7
and $8, $9, $10
slt $11, $12, $5
beq $13, $14, Loop
add $15, $16, $17
With reorder
Loop: add
sub $4, $5, $1
nop
or $5, $6, $7
and $8, $9, $10
slt $11, $12, $5
beq $13, $14, Loop
add $15, $16, $17
Reordering can not reduce the number of nops
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.