Skip to content
Official PYQ · 2005

GATE CS 2005 Q68 — Instruction Pipelining

Explain with AI

A 55 stage pipelined CPU has the following sequence of stages:

  • IF – instruction fetch from instruction memory
  • RD – Instruction decode and register read
  • EX – Execute: ALU operation for data and address computation
  • MA – Data memory access – for write access, the register read at RD state is used.
  • WB – Register write back

Consider the following sequence of instructions:

  • I1I_1: LL R0,locR0, loc 11; R0⇐M[loc1]R0 \Leftarrow M[loc1]
  • I2I_2: AA R0R0, R0R0; R0⇐R0+R0R0 \Leftarrow R0 +R0
  • I3I_3: SS R2R2, R0R0; R2⇐R2−R0R2 \Leftarrow R2-R0

Let each stage take one clock cycle.

What is the number of clock cycles taken to complete the above sequence of instructions starting from the fetch of I1I_1?

Choose one option
View worked solution

Answer: A

To find the number of clock cycles, we analyze the dependencies between instructions assuming standard operand forwarding is supported:

  • I1→I2I_1 \rightarrow I_2 (Load-Use Hazard): I1I_1 is a load instruction (R0⇐M[loc1]R0 \Leftarrow M[loc1]). The data for R0R0 is only available at the end of the MA stage of I1I_1. Since I2I_2 needs R0R0 at the beginning of its EX stage, I2I_2 must stall for 11 clock cycle in its RD stage. The operand is then forwarded from the MA/WB register of I1I_1 to the EX stage of I2I_2.
  • I2→I3I_2 \rightarrow I_3 (ALU-ALU Dependency): I2I_2 is an arithmetic instruction (R0⇐R0+R0R0 \Leftarrow R0 + R0). The result is available at the end of the EX stage of I2I_2. Since I3I_3 needs R0R0 for its EX stage, the value can be forwarded directly from the EX/MA register of I2I_2 to the EX stage of I3I_3 without any stalls.

The cycle-by-cycle pipeline execution is shown below:

Clock Cycle I1I_1 I2I_2 I3I_3
1IF
2RDIF
3EXRDIF
4MARD (stall)IF (stall)
5WBEXRD
6MAEX
7WBMA
8WB

Thus, the sequence of instructions completes in 8 clock cycles.

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

Published
Report a correction
Keep exploringMore Instruction Pipelining questions