Home / Learn Verilog / Project 13: 8-bit CPU in Verilog

Project 13: 8-bit CPU in Verilog

Tiny accumulator CPU with ROM program.

The short versionTiny accumulator CPU with ROM program.

Theory in plain words

CPUPCROMdecodeALU+accPC
CPU

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.

LevelTimeWorks in simulation only?
Advanced12 hoursSimulation 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.

ItemWhat it is (in simple words)Why you need itApprox. 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 resistorsAn 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

SignalDirectionGoes toNote
clkinputslow clock from a dividerabout 2 Hz to watch
acc[7:0]outputLEDsshows accumulator

Step 1: simulate the design

Accumulator CPUVerilog: edit and run

This starter shows the datapath idea (counter, sum, halt). Extend it with a real ROM and instruction decoder in the steps.

Step by step

  1. Define the instruction format (4-bit opcode, 4-bit operand).
  2. Write the ROM as a case statement or memory.
  3. Add states FETCH, DECODE, EXECUTE.
  4. Write a testbench that runs the program and checks the accumulator.
  5. Show the accumulator on LEDs at 2 Hz.

If it does not work

SymptomLikely causeFix
Board not detectedCharge-only cable or no driverUse a data cable, install the vendor driver
Nothing happensWrong pin constraintsRecheck every pin against the board manual
CPU runs wildPC not resetReset PC and state
Wrong resultInstruction decode priorityPrint pc and ir every cycle
Tip:Keep your first board test tiny: if the LED blinks, the toolchain, cable and clock are fine. Then add your project piece by piece.

Quick quiz

1. Fetch step does...