A 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:
- : ;
- : , ;
- : , ;
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 ?
View worked solution
Answer: A
To find the number of clock cycles, we analyze the dependencies between instructions assuming standard operand forwarding is supported:
- (Load-Use Hazard): is a load instruction (). The data for is only available at the end of the MA stage of . Since needs at the beginning of its EX stage, must stall for clock cycle in its RD stage. The operand is then forwarded from the MA/WB register of to the EX stage of .
- (ALU-ALU Dependency): is an arithmetic instruction (). The result is available at the end of the EX stage of . Since needs for its EX stage, the value can be forwarded directly from the EX/MA register of to the EX stage of without any stalls.
The cycle-by-cycle pipeline execution is shown below:
| Clock Cycle | |||
|---|---|---|---|
| 1 | IF | ||
| 2 | RD | IF | |
| 3 | EX | RD | IF |
| 4 | MA | RD (stall) | IF (stall) |
| 5 | WB | EX | RD |
| 6 | MA | EX | |
| 7 | WB | MA | |
| 8 | WB |
Thus, the sequence of instructions completes in 8 clock cycles.
Free practice · Your answers on this page are not saved.
