Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN MIPS ASSMEBLY Use the following code fragment Loop: LW R1,0(R2) ADDI R1,R1,1

ID: 3718182 • Letter: I

Question

IN MIPS ASSMEBLY

Use the following code fragment Loop: LW R1,0(R2) ADDI R1,R1,1 SW R1, 0(R2) ADDI R2,R2,4 SUB R4,R3,R2 BNEZ R4, Loop ;load R1 from address 0+R2 R1-R1+1 store R1 at address 0+ ;R2-R2+4 ;R4-R3-R2 ,branch to Loop if R41-e Assume that the initial value of R3 is R2396 Further assume that the branch addresses are calculated during the ID phase and branch prediction is handled as designated in the tables 2.1 of the appendix. a. Data hazards are caused by data dependences in the code. List all of the data dependences in the code above. Record the register, source instruction, and destination instruction; for example, there is a data dependency for register R1 from the LW to the ADDI b. Show the timing of this instruction sequence for the 5-stage RISC pipeline without any forwarding or bypassing hardware but assuming that a register read and a write in the same clock cycle "forwards" through the register file. Assume that the branch is handled by flushing the pipeline. If all memory references take 1 cycle, how many cycles does this loop take to execute?

Explanation / Answer

Answer :

a) Data dependencies :

b) Pipeline without forwarding and byPassing :

Total Cycles = 19

Cycles-> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 lwr1,0(r2) IF ID EX MEM WB addi r1,r1,1 IF * * ID EX MEM WB sw r1,0(r2) IF * * ID EX MEM WB addi r2,r2,4 IF * * ID EX MEM WB sub r4,r3,r2 IF * ID EX MEM WB bnez r4,loop IF * * ID EX MEM WB