Home / Learn Verilog / Project 13: 8-bit CPU in Verilog
Project 13: 8-bit CPU in Verilog
Tiny accumulator CPU with ROM program.
Theory in plain words
In plain terms
Design a tiny CPU with fetch, decode, execute: LOAD, ADD, STORE, JMP, JNZ, HALT. Run a program that sums 1 to 5.
Why we use it
Projects turn knowledge into skill: you design, simulate, debug and finally see real hardware react.
Under the hood
Simulate in the browser, then build for your board following the steps.
Real-world use
- Portfolio
- Interviews
- Learning by doing
What you will build
Design a tiny CPU with fetch, decode, execute: LOAD, ADD, STORE, JMP, JNZ, HALT. Run a program that sums 1 to 5.
| Level | Time | Works in simulation only? |
|---|---|---|
| Advanced | 12 hours | Simulation first; LEDs optional |
What you need (equipment and tools)
Read this table once and you will know exactly what to buy or prepare. You can do the simulation part with only a computer and the free tools.
| Item | What it is (in simple words) | Why you need it | Approx. cost |
|---|---|---|---|
| Computer (Windows, Linux or macOS) | Your normal laptop or desktop. You write Verilog here and run the free tools. | Simulator, synthesis and programmer all run on it. | you have it |
| Free software: Icarus Verilog + GTKWave (simulation), Yosys + nextpnr or the vendor IDE (build), openFPGALoader (program) | The programs that compile and simulate your design. | Everything in this course can be simulated with only these free tools. | free |
| FPGA development board (e.g. Tang Nano 9K, Basys 3, iCEBreaker, Arty A7) | A small circuit board with an FPGA chip, an oscillator (clock), LEDs, buttons and a USB port. The FPGA is the "blank hardware" that your Verilog turns into a real circuit. | This is where your design actually runs. Without it you can only simulate. | about $15 (Tang Nano 9K) to $150 (Arty A7) |
| LEDs (5 mm) + 330 ohm resistors | An LED lights when current flows through it. The resistor limits that current so the LED and the FPGA pin do not burn. | Visible output. Many boards already have LEDs built in; external ones are for bigger demos. | $2 for a pack |
| Push buttons (tactile switches) | A small switch that connects two pins while pressed. | Your input to the design. They bounce, so the design needs a debouncer. | $1 |
Connections
| Signal | Direction | Goes to | Note |
|---|---|---|---|
| clk | input | slow clock from a divider | about 2 Hz to watch |
| acc[7:0] | output | LEDs | shows accumulator |
Step 1: simulate the design
This starter shows the datapath idea (counter, sum, halt). Extend it with a real ROM and instruction decoder in the steps.
Step by step
- Define the instruction format (4-bit opcode, 4-bit operand).
- Write the ROM as a case statement or memory.
- Add states FETCH, DECODE, EXECUTE.
- Write a testbench that runs the program and checks the accumulator.
- Show the accumulator on LEDs at 2 Hz.
If it does not work
| Symptom | Likely cause | Fix |
|---|---|---|
| Board not detected | Charge-only cable or no driver | Use a data cable, install the vendor driver |
| Nothing happens | Wrong pin constraints | Recheck every pin against the board manual |
| CPU runs wild | PC not reset | Reset PC and state |
| Wrong result | Instruction decode priority | Print pc and ir every cycle |
Quick quiz
1. Fetch step does...
PC addresses ROM.