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 idea, explained simply
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.
| Level | Time | Works in simulation only? |
|---|---|---|
| Advanced | 10 hours | Simulation |
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 |
| 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
| Signal | Direction | Goes to | Note |
|---|---|---|---|
| clk | input | board clock | |
| uart_tx | output | USB-serial RX | print registers |
Step 1: simulate the design
Register x0 must always read as 0 even if you write to it.
Step by step
- Simulate the register file and ALU.
- Add the instruction decoder for R-type and I-type ADD.
- Add the PC and instruction ROM.
- Run a tiny program in simulation and print registers.
- Print register values over UART.
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 |
| x0 not zero | Write enable not blocked | Block writes to register 0 |
| Wrong subtraction | op mapping | Check opcode table |
Test what you just read
1. RISC-V register x0 is...
Hard-wired to 0.