GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A classic 5-stage pipeline (IF, ID, EX, MEM, WB) has no forwarding and no split-cycle register file: a value written in WB can be read in ID only in the next cycle. Branches are resolved in EX; a taken branch flushes the two instructions fetched after it and the target is fetched in the next cycle. Without hazards I1 finishes WB in cycle 5. Program: I1: LW R1, 0(R9); I2: LW R2, 4(R9); I3: ADD R3, R1, R2; I4: BEQ R3, R0, L2; I5: SUB R4, R3, R1; I6: ADD R5, R4, R2; I7 (label L2): SW R5, 8(R9). The BEQ is taken. In which cycle does the last instruction finish WB?

  1. A. 23
  2. B. 15
  3. C. 20
  4. D. 17

Correct answer: D. 17

A consumer's ID must come at least 4 cycles after its producer's ID (one cycle after the WB). ID cycles: I1 2, I2 3, I3 7, I4 11, I7 14. I4 waits for R3; the taken branch skips I5 and I6, so the SW only waits for the redirect (branch ID + 3) and uses the old R5. WB = 17. Not taken, the chain I5 → I6 → I7 gives 23; with a split-cycle register file it would be 15.

More Computer Organization and Architecture questions

Exams that ask this topic