6. Insert an appropriate number of NOPs in the following code to eliminate as ma
ID: 3905398 • Letter: 6
Question
6. Insert an appropriate number of NOPs in the following code to eliminate as many hazards as possible. The MIPS pipeline for this question does not support forwarding: lw $s0, 4($t0) add $s1, $s0, $t0 addi $s2, $s1, 5 or $s3, $zero, $s1 sw $s2, 8($t0) 7. Reorder instructions or insert an appropriate number of NOPs in the following code to eliminate as many hazards as possible. The MIPS pipeline for this question does not support forwarding. Only insert if it is not possible to reorder instructions: NOPs sub $t5, $t4, $t3 lw $s0, 4($t0) add $s3, $t1, $t2 add $s1, $s0, $t0 lw $t3, 0($s1) subi $s2, $s1, 5 or $s3, $s2, $sl sw $s2, 80$t0) 8. Why do branch delay slots occur in the MIPS pipeline? Can the following code be modified to avoid the use of NOPs? If not, how many NOPs are needed? add $s0, $s1, $s2 sub $s3, $s2, $s1 j labelExplanation / Answer
6.
Consider instruction as I1, I2.... I5. Here we are having data dependency between I1 and I2 due to s0 and between I2 AND I3 due to s1
Space time diagram for given code (N=NOP)
Hence 6 nop is required.
7.
I1: sub $t5, $t4, $t3
I2:lw $s0,4($t0)
I3:add $s3, $t1,$t2
I4:add $s1, $s0, $t0
I5:lw $t3, 0($s1)
I6:subi $s2,$s1,5
I7:or $s3, $s2, $s1
I8:sw $s2, 8($t0)
New order of execution.
I2:lw $s0,4($t0)
I1: sub $t5, $t4, $t3
I3:add $s3, $t1,$t2
NOP
I4:add $s1, $s0, $t0
I6:subi $s2,$s1,5
NOP
NOP
NOP
NOP
I5:lw $t3, 0($s1)
I6:subi $s2,$s1,5
NOP
NOP
NOP
NOP
I7:or $s3, $s2, $s1
I8:sw $s2, 8($t0)
8
MIPS uses 5 stage pipeline.These stages are IF,ID,EX,MA,WB. Stage 2 is Instruction decode and operand fetch.
When we are executing branch instruction branch target is known at 2nd stage(ID: At this stage only we update PC with target address) until then next instruction in the pipeline will be fetched which make out of order execution .To prevent this we insert delay slots after the branch instruction.
We can prevent delay slot in this program by rearranging the code.
add $s0, $s1, $s2
j label
sub $s3 $s2,$s1
1 2 3 4 5 6 7 8 9 10 12 13 14 15 WB I1 N N N I2 N N N I3 I4 MA I1 N N N I2 N N N I3 I4 I5 EX I1 N N N I2 N N N I3 I4 I5 ID I1 N N N I2 N N N I3 I4 I5 IF I1 N N N I2 N N N I3 I4 I5Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.