RISC Microarchitecture: part 5 of the course

Released — the 20 levels 48–67 are playable in the game, with guides in the library.

After 47 levels you can build a computer that runs a program. The next step is course part 5, the RISC Lab module: build a 32-bit RISC processor on an RV32I teaching subset in Verilog and take it to a five-stage pipeline — with forwarding, load bubbles, and wrong-path flushes that you detect and resolve yourself.

What changes after Part 4

In Parts 1–4 you built the processor around an accumulator: almost every instruction read it, did something with it, and wrote it back. That is convenient for the first steps and inconvenient for speed, because two instructions cannot work at once while both hold the same register.

Part 5 rebuilds the machine around a different model:

The difference shows on a simple example. The expression (A + B) − (C + D) on the course machine is a chain through the accumulator: load, add, store to a temporary cell, load again. On a register machine, with the values already in registers, it is three instructions — add, add, sub — and the two adds no longer share one register, so a pipeline can overlap them. Part 5 shows what that takes.

The five pipeline stages of RISC Lab Left to right: IF — instruction fetch, ID — decode and register read, EX — execute in the ALU, MEM — memory access, WB — write the result back to a register. IF fetch ID decode EX ALU MEM memory WB write-back register register register register

Three principles of the stage

The Part 5 levels work differently from those in Parts 1–2. There, the check compared a circuit against a truth table. Here the mistake is usually not in a single gate but in how the stages agree with each other, and it shows only in behaviour over time.

  1. Productive failure. First you build a naive pipeline and run a real program on it. The result is wrong. Then you look for the cause in the waveform: which stage, on which cycle, received the wrong value. Before the check you predict the result or the trace — the rule appears as a conclusion from observation, not as a ready answer in the task.
  2. Open control logic. The Control Unit, Forwarding Unit, and Hazard Unit are Verilog blocks you write yourself. What counts as "the source is ready", "a conflict", or "a bubble" is something you state in terms of signals rather than take on trust.
  3. Engineering trade-off. A pipeline is not free: it speeds up some programs and complicates the circuit. Every step tracks two metrics — cycles per instruction (CPI) and circuit cost: propagation delay and gate count.

The route: twenty levels

The route has two independent arcs. The first is the single-cycle core: from the register file to a working processor running a program on the LEDs. The second is the pipeline: the same core cut into five stages, with three kinds of hazard, one per level.

Single-cycle core — levels 48–60

48

Farewell, Accumulator!

From the accumulator to a register machine: 32 registers, x0 hardwired to zero, three addresses per instruction.

49

Anatomy of an R-type Instruction

The fields of a 32-bit instruction and a 32×32 register file: two reads and one write per cycle.

50

A 32-bit ALU

Arithmetic, logic, shifts, signed and unsigned comparisons, and the Zero flag for branches.

51

A Constant Inside the Instruction

The I-format, sign extension, and a mini-assembler that turns mnemonics into machine words.

52

Memory by the Rules

A load/store architecture: arithmetic on registers only, LW/SW, and four-byte alignment.

53

A Step of Four

PC+4, the split-immediate B-format, and the first conditional branch, BEQ.

54

A Loop on BNE

A counter, a comparison, and BNE: the first loop on your own machine, with a cycle-count prediction.

55

Array Sum

A real program: the array base via LUI+ADDI, a walk over elements with LW, and a running sum.

56

Call and Return

JAL and JALR: the return address in ra, functions, and a nested call that saves ra in memory.

57

Nested Calls and the Stack

ra and sp, the function prologue and epilogue, nested calls: the frame grows downward through memory.

58

Assembling RV32I

The complete single-cycle core of the RV32I teaching subset: PC, instruction memory, decoder, registers, ALU, data memory, control.

59

Knight Rider RISC

A running light on the LEDs through MMIO, plus a project export for the Tang Nano 9K.

60

The Verification Lab

Scenario verification: inputs, expected states, a trap for a planted bug, and a regression run after the fix.

The pipeline — levels 61–67

61

Why the Cycle Is Long

The single-cycle critical path, a map of the five stages, and the price of every cycle.

62

Between Stages

Four pipeline registers: data, control signals, and rd travel together.

63

Five Instructions in Flight

Reading the trace: the pipeline diagram, fill and drain, and which instruction is where on cycle k.

64

The Short Path

RAW forwarding: the ALU result feeds the next instruction directly, with priorities and the x0/lw exceptions.

65

The Load Bubble

The load-use hazard that cannot be forwarded: the detector inserts exactly one bubble, freezing PC and IF/ID.

66

Ghosts of the Wrong Path

The branch resolves in EX: a taken branch flushes two ghosts fetched along the old path — a 2-cycle price.

67

Knight Rider Pipeline

The course finale: Knight Rider on the full pipelined core, hazard prices in cycles, and CPI compared with the single-cycle machine.

Learning outcomes

After the stage a student can:

For teachers

Part 5 follows Part 4 and builds on it: by then the student has already built a control unit, a custom instruction set, and a datapath in Verilog. The pipeline introduces no new gates; it introduces a new requirement on how familiar blocks are organised.

The module splits into three lessons: the single-cycle RISC (48–60), the pipeline (61–63), and hazards (64–67). The key check of understanding is that the same program (a counter, Fibonacci, an array sum) gives the same result on the single-cycle and the pipelined core, while the modes without forwarding, stall, or flush fail on it.

Open control logic gives a second point of assessment: the forwarding rule, the stall condition, and the flush point must be written in terms of the circuit's signals. Such a rule can be tested on new programs, not only on the one where it was invented.

The methodological overview of the trajectory is the "RISC Lab: levels 48–67" teacher card.

Status and scope

Next steps

Open level 48 →