Built a complete 32-bit MIPS processor from scratch, starting from a single
logic gate, assembling a full adder, scaling to a 32-bit ALU, and finishing
with a CPU that executes real assembly programs including an integer division
routine. Written in Veryl, a modern hardware description language that
compiles to SystemVerilog.
VerylSystemVerilogMIPSDigital LogicHDLVerilator
Course labs
L2
Combinational Logic & BCD Checker
Designed logic circuits in Veryl for a 4-bit BCD digit checker that computes max, min, even, lo3, noBCD, and hieq3 from boolean expressions. Visualised netlists in DigitalJS via Yosys, performed Karnaugh minimisation, and implemented PLD cell arrays. Verified every output using Verilator testbenches with exhaustive assertions.
L3a
4-bit ALU: Full Adder → Arithmetic + Logic Unit
Built a 1-bit full adder, chained four into a ripple-carry adder, then wrapped it in an arithmetic unit supporting ADD and SUB with signed overflow (V) and carry (C) flags. Added a 4-bit logic unit for AND and OR. Verified signed and unsigned arithmetic edge cases with complete truth tables and simulation waveforms.
L3b
32-bit ALU + Program Counter
Scaled the 4-bit ALU to 32 bits using a generate loop over 32 full adders. Extended it with AND, OR, and SLT via a 4-to-1 mux, plus a zero flag (Z). Designed a clocked program counter that increments by 4 each cycle with async reset, the first sequential component in the processor.
L4
Simplified Single-Cycle MIPS Processor
Wired everything together: instruction memory, register file, sign-extend unit, control decoder, ALU, and muxes in a top-level module. Implemented the full MIPS single-cycle datapath for 7 instructions: ADD, SUB, AND, OR, SLT, ADDI, SLTI. Wrote a testbench that steps through the program and asserts correct register values every clock cycle.
L5
Full MIPS: Data Memory, Branch, Jump & Integer Division
Added data memory (LW/SW), branch (BEQ with signed offset × 4), and jump (J with 26-bit absolute target). Wrote MIPS assembly for integer division using repeated subtraction and hand-translated it to machine code. The final processor executes the full program and stores quotient + remainder in data memory, verified by assertions in the testbench.
Interactive demos
Reproduction of the Lab 2 BCD checker. Toggle the 4 input bits and see all
six combinational outputs update instantly, using the exact same boolean expressions
as the Veryl module.
x3
x2
x1
x0
Input: 0000 = 0
max0
min0
even0
lo30
noBCD0
hieq30
The 32-bit ALU from Lab 3b. Enter two values in hex, pick an operation, and
see the result plus the overflow (V), carry (C), and zero (Z) flags, computed
the same way as the Veryl hardware.
Input A (hex)
8 (unsigned) · 8 (signed)
Input B (hex)
5 (unsigned) · 5 (signed)
Operation
0x0000000D
Unsigned: 13
Signed: 13
V = 0C = 0Z = 0
A JavaScript port of the MIPS processor from Labs 4 and 5, using the same
instruction set and datapath logic. Step through or auto-run and watch the register file
update live.
PC: 0x00 · Cycle: 0
Register File (r0-r9)
Program Complete
Selected source files from all five labs, written in Veryl.
What I learned
A processor is small parts put together.
The same full adder that adds two bits is used for the 32-bit ALU, for moving the program counter on by four, and for working out where a branch goes.
Control signals do the choosing.
Every instruction goes through the same hardware. The decoder only sets a few signals that pick register or constant, ALU or memory, and whether to write the result.
Addresses are cut and glued.
A branch uses a sign-extended offset times four, while a jump keeps the top bits of the program counter and fills in the rest. Getting one bit wrong sends the program somewhere else.