The five stages
- IF — fetches the instruction at the PC and advances the PC.
- ID — decodes and reads the source registers. Hazards are detected here.
- EX — the ALU computes the result, the memory address or the branch condition.
- MEM — loads and stores access memory.
- WB — the result is written to the destination register.
How to read the diagram
Each row is a stage and each column a clock cycle; the cell says which instruction occupies that stage in that cycle. With three independent instructions there are no waits: the first one finishes in cycle 5 and then one comes out per cycle.
| Stage | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| IF | I0 | I1 | I2 | — | — | — | — |
| ID | — | I0 | I1 | I2 | — | — | — |
| EX | — | — | I0 | I1 | I2 | — | — |
| MEM | — | — | — | I0 | I1 | I2 | — |
| WB | — | — | — | — | I0 | I1 | I2 |
Without hazards, N instructions take N + 4 cycles: 4 to fill the pipeline and then one per cycle. Any cycle above that is a penalty, and the diagram shows where it happens: a bubble is an empty stage inserted while an instruction waits in ID, and FLUSH is an instruction discarded after a branch.