A pipelined processor uses a 4-stage instruction pipeline with the following stages: Instruction fetch (IF),…
ASHI DUBEY
A pipelined processor uses a 4-stage instruction pipeline with the following stages: Instruction fetch (IF), Instruction decode (ID), Execute (EX) and Writeback (WB). The arithmetic operations as well as the load and store operations are carried out in the EX stage. The sequence of instructions corresponding to the statement X = (S - R * (P + Q))/T is given below. The values of variables P, Q, R, S and T are available in the registers R0, R1, R2, R3 and R4 respectively, before the execution of the instruction sequence.ADD R5, R0, R1 MUL R6, R2, R5
SUB R5, R3, R6DIV R6, R5, R4STORE R6, X
The IF, ID and WB stages take 1 clock cycle each. The EX stage takes 1 clock cycle each for the ADD, SUB and STORE operations, and 3 clock cycles each for MUL and DIV operations. Operand forwarding from the EX stage to the ID stage is used. The number of clock cycles required to complete the sequence of instructions is
So, I came across the above PYQ, and my doubt is, since it is mentioned in the above question that "Operand forwarding from the EX stage to the ID stage is used", shouldn't ID stage of the current instruction be the one to receive the operands from the previous instruction's EX stage in case of data dependency. Although normally we pass the operands from EX to EX but since, it is mentioned here, shouldn't it be passed to the ID stage? making the answer = 15 clocks. Solution below. Please correct me if i have misinterpreted the sentence!
Inst | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
---------------------------------------------------------------------------------
I1 | IF | ID | E | W | | | | | | | | | | | |
I2 | | IF | X | ID | E | E | E | W | | | | | | | |
I3 | | | | IF | X| X | X | ID | E | W | | | | | |
I4 | | | | | | | | IF | X | ID | E | E | E | W | |
I5 | | | | | | | | | | IF | ID | X | X | E | W |
