A stage pipelined processor has Instruction Fetch (IF), Instruction Decode (ID), Operand Fetch (OF), Perform Operation (PO) and Write Operand (WO) stages. The IF, ID, OF and WO stages take clock cycle each for any instruction. The PO stage takes clock cycle for ADD and SUB instructions, clock cycles for MUL instruction and clock cycles for DIV instruction respectively. Operand forwarding is used in the pipeline. What is the number of clock cycles needed to execute the following sequence of instructions?
View worked solution
Answer: B
To find the total number of clock cycles, we must trace the execution of each instruction through the 5-stage pipeline: IF, ID, OF, PO, and WO.
Since the PO stage is non-pipelined and takes multiple cycles (3 for MUL, 6 for DIV), it can cause structural hazards. Additionally, data hazards are resolved using operand forwarding, which allows a dependent instruction to receive its operand immediately after the producer's PO stage completes.
The cycle-by-cycle execution is shown in the table below:
| Instruction | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| : MUL | IF | ID | OF | PO | WO | ||||||||||
| : DIV | IF | ID | stall (OF) | PO | WO | ||||||||||
| : ADD | IF | stall (ID) | stall (OF) | PO | WO | ||||||||||
| : SUB | IF | stall (ID) | OF | PO | WO |
Key Details:
- (DIV) is stalled in the OF stage during cycles 4–6 because the PO stage is occupied by (structural hazard).
- (ADD) requires from . Since 's PO stage finishes at the end of cycle 12, is forwarded to at the start of cycle 13. Thus, stalls in OF during cycles 7–12.
- (SUB) requires from . Since 's PO stage finishes at the end of cycle 13, is forwarded to at the start of cycle 14.
Thus, the total execution time is 15 clock cycles.
Free practice · Your answers on this page are not saved.
