Master the fundamental concepts of cpu design through this focused micro-challenge.
Modern teaching pipelines use IF (fetch), ID (decode), EX (execute), MEM (memory), and WB (writeback). Each stage advances every cycle, so five instructions can be in flight at once when the pipe is full.
cLoading…
| Stage | Job |
|---|---|
| IF | Read instruction at PC |
| ID | Decode, read registers |
| EX | ALU, address calc |
| MEM | Load/store data |
| WB | Write register result |
Load-use hazards are the classic pain: a LOAD in EX produces data in MEM, but the next instruction needs it in EX one cycle later. You must stall one cycle or forward from MEM/WB.
For this exercise, you will refactor your CPU into five pipeline registers. You will need stage-accurate PC and register updates to match textbook timing diagrams before adding forwarding to remove unnecessary stalls.
Keep the relevant datasheet, ISA manual, or architecture textbook chapter open while you implement. When your output disagrees with the reference trace on the same program, the bug is usually a mis-decoded opcode, a stale register read, or a flag bit left unchanged after arithmetic.
For this exercise, you will use those habits while implementing the requirement in the starter code. Microarchitectural product names change across CPU generations, but the control ideas (fetch, bypass, cache lines, vector lanes) stay stable enough to debug from first principles.
Implement 5-stage pipeline with hazard detection and forwarding.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github