For the given instruction sequence is it possible to resolve any of the data haz
ID: 3738991 • Letter: F
Question
For the given instruction sequence is it possible to resolve any of the data hazards by reordering the instructions so that forwarding would be unnecessary? (Select all that apply.)
add $t0, $s0, $s1
xor $t1, $t0, $s2
lw $s0, -12($a0)
sub $s5, $s0, $s1
A.
add $t0, $s0, $s1
lw $s0, -12($a0)
sub $s5, $s0, $s1
xor $t1, $t0, $s2
B.
lw $s0, -12($a0)
add $t0, $s0, $s1
xor $t1, $t0, $s2
sub $s5, $s0, $s1
C.
xor $t1, $t0, $s2
add $t0, $s0, $s1
sub $s5, $s0, $s1
lw $s0, -12($a0)
D.
add $t0, $s0, $s1
xor $t1, $t0, $s2
sub $s5, $s0, $s1
lw $s0, -12($a0)
Explanation / Answer
Data Hazard : It is a problem in instruction pipeline when next instruction needs results computed from previous instruction but previous instruction doesnot computes results till the time next instruction needs that results, which leads to data inaccuracy.
Code-Reordering: It is a solution to data hazard problem. In this, code is ordered in such a way that dependent instructions computes result accurately.
Given instruction :
add $t0, $s0, $s1
xor $t1, $t0, $s2
lw $s0, -12($a0)
sub $s5, $s0, $s1
Here, xor instruction is dependent on add instruction as xor reads $t0 which stores results of add instruction.
So, re-ordering can lead to :
add $t0, $s0, $s1
lw $s0, -12($a0)
sub $s5, $s0, $s1
xor $t1, $t0, $s2
One more dependent statement is there i.e. sub instruction needs $s0 which is result of lw instruction.
So, 2nd re-ordering :
lw $s0, -12($a0)
add $t0, $s0, $s1
xor $t1, $t0, $s2
sub $s5, $s0, $s1
So, A and B are 2 re-orderings.