This is the MIPS code :
(1) Loop : lw $2, 0($1)
(2) lw $3, 0($2) # $2
(3) add $4, $3, $2 # $3, $2
(4) sw $4, 4($2) # $4
(5) beq $4, $5, Loop # $4
For identifying all the RAW dependencies in the code, I think that $2 in instruction 2 and 3 have RAW dependency to $2 in instruction 1. And $3 in instruction 3 has RAW dependency to $3 in instruction 2. Lastly, $4 in instruction 4 and 5 have RAW dependency to $4 in instruction 3. I don't know if this is right or not.
Question : Assume the pipelined processor provides full forwarding but no hazard detection logic. Assume branch target address calculation and resolution is done in ID and the last beq instruction is taken. Please insert "nop" between instructions and after beq if needed to avoid the hazards. [hint : you can insert two nops if you need two stall cycles]
First, I'm not sure If I checked all the RAWs right or not. and Second, I have no idea where to put nop(s) in the code, I only inserted nop in the codes that are not in loop. please help me with this. Thank you
- I edited again thanks to the comment. I'm not used to stackoverflow