Consider a pipelined processor with the following four stages: IF: Instruction…

2007

Consider a pipelined processor with the following four stages:

IF: Instruction Fetch
ID: Instruction Decode and Operand Fetch
EX: Execute
WB: Write Back

The IF, ID and WB stages take one clock cycle each to complete the operation. The number of clock cycles for the EX stage depends on the instruction. The ADD and SUB instructions need 1 clock cycle and the MUL instruction needs 3 clock cycles in the EX stage. Operand forwarding is used in the pipelined processor. What is the number of clock cycles taken to complete the following sequence of instructions?

ADD R2, R1, R0    R2 <- R0 + R1
MUL R4, R3, R2    R4 <- R3 * R2
SUB R6, R5, R4    R6 <- R5 - R4

  1. A.

    7

  2. B.

    8

  3. C.

    10

  4. D.

    14

Attempted by 15 students.

Show answer & explanation

Correct answer: B

With forwarding, the dependent instruction can use the produced value in its EX stage, but the single EX stage is occupied by MUL for 3 cycles. A valid schedule is: cycle 1 ADD-IF; cycle 2 ADD-ID and MUL-IF; cycle 3 ADD-EX, MUL-ID, SUB-IF; cycle 4 ADD-WB and MUL-EX1; cycles 5-6 MUL-EX2/EX3 while SUB waits; cycle 7 MUL-WB and SUB-EX; cycle 8 SUB-WB. Therefore the sequence completes in 8 clock cycles.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir