Home / Learn Verilog / Project 14: Mini RISC-V ALU and Register File

Project 14: Mini RISC-V ALU and Register File

Register file, immediate decode and ALU for 4 instructions.

The gistRegister file, immediate decode and ALU for 4 instructions.

The idea, explained simply

Mini RISC-VROMdecoderegfileALUwriteback
Mini RISC-V

Definition

Build the core blocks of a RISC-V style CPU: 32x32 register file with x0 = 0, ALU for ADD/SUB/AND/OR, and an immediate decode.

Why you need this

Projects turn knowledge into skill: you design, simulate, debug and finally see real hardware react.

How it works

Simulate in the browser, then build for your board following the steps.

Where you'll see this

  • Portfolio
  • Interviews
  • Learning by doing

What you will build

Build the core blocks of a RISC-V style CPU: 32x32 register file with x0 = 0, ALU for ADD/SUB/AND/OR, and an immediate decode.

LevelTimeWorks in simulation only?
Advanced10 hoursSimulation

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
USB-to-serial adapter (CP2102, CH340 or FT232, 3.3 V level)A small dongle that turns USB into TX/RX pins that a UART design can talk to.Lets the PC send/receive bytes with your design in a terminal program.$3

Connections

SignalDirectionGoes toNote
clkinputboard clock
uart_txoutputUSB-serial RXprint registers

Step 1: simulate the design

Register file + ALUVerilog: edit and run

Register x0 must always read as 0 even if you write to it.

Step by step

  1. Simulate the register file and ALU.
  2. Add the instruction decoder for R-type and I-type ADD.
  3. Add the PC and instruction ROM.
  4. Run a tiny program in simulation and print registers.
  5. Print register values over UART.

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
x0 not zeroWrite enable not blockedBlock writes to register 0
Wrong subtractionop mappingCheck opcode table
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.

Test what you just read

1. RISC-V register x0 is...