Skip to content
Official PYQ · 2008

GATE CS 2008 Q77 — Instruction Pipelining

Explain with AI

Delayed branching can help in the handling of control hazards

The following code is to run on a pipelined processor with one branch delay slot:

I1: ADD R2←R7+R8R2 \leftarrow R7 + R8

I2: Sub R4←R5–R6R4 \leftarrow R5 – R6

I3: ADD R1←R2+R3R1 \leftarrow R2 + R3

I4: STORE Memory [R4]←R1[R4] \leftarrow R1

     BRANCH to Label if R1==0R1 == 0

Which of the instructions I1, I2, I3 or I4 can legitimately occupy the delay slot without any program modification?

Choose one option
View worked solution

Answer: D

In a pipelined processor with a branch delay slot, the instruction placed in the delay slot is always executed, regardless of whether the branch is taken or not.

To safely move an instruction into the branch delay slot from before the branch without modifying the program behavior, the following conditions must be met:

  1. Data Dependency: No instruction remaining before the branch can depend on the instruction moved to the delay slot.
  2. Branch Dependency: The branch condition must not depend on the instruction in the delay slot.

Let's analyze the instructions:

  • I1 cannot be moved because I3 depends on R2R2 produced by I1.
  • I2 cannot be moved because I4 depends on R4R4 produced by I2.
  • I3 cannot be moved because the BRANCH condition depends on R1R1 produced by I3.
  • I4 can be safely moved because no instruction between I4 and the BRANCH depends on it, and it does not affect the branch condition. Since I4 was executed before the branch in the original sequence, executing it in the delay slot (where it always executes) preserves the program semantics.

Therefore, I4 is the only instruction that can legitimately occupy the delay slot.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Instruction Pipelining questions