RTL Studio Open IDE

2.1 · RISC-V CLASS

Register file with hardwired x0

Build the 2-read / 1-write integer register file with x0 tied to zero.

Video coming soon. This lesson page stays at the same URL when the lecture publishes.

What you practice

Register file with hardwired x0 (2.1). Build the 2-read / 1-write integer register file with x0 tied to zero. It is in Register file x0..x31 — Part 2 · Execute Path of the RISC-V RV32I Core Masterclass.

The RV32I core is Verilog you simulate in the browser IDE. Verilator runs the program; the waveform shows PC, the instruction, and the register write.

What you will learn

Today you will implement the integer register file for the RV32I base ISA. You will learn how to hardwire register x0 to zero and prevent writes to it. This is a fundamental building block for any RISC-V processor.

Learning objectives

  • Implement a 32-entry register file with two read ports and one write port.
  • Hardwire register x0 to always read as zero.
  • Prevent any write operation from modifying register x0.
  • Verify the design using a testbench that checks x0 immutability.

Theory

The RISC-V ISA specifies that register x0 is hardwired to zero. Any read from x0 must return 0. Any write to x0 must be ignored. The register file must support two simultaneous reads and one write per clock cycle. The write is gated by a write enable signal and a destination address check. The read ports use multiplexers to select between the stored value and 0 when the address is 0. This ensures that x0 behaves correctly without needing a physical storage element for it.

Practice

Open this chapter in RtlStudio. Files appear in Explore. Edit student/rtl/ip/riscv/rv32i_regfile.sv. Open student/tb/tb_top.sv to see the testbench. Run Simulation from the sidebar. Read the Log panel. Open the Waveform tab to inspect signals if needed.

In student/rtl/ip/riscv/rv32i_regfile.sv, replace the __TODO__ placeholders. Initialize all registers to zero on reset. Guard the write to prevent updating x0. Use a ternary operator to return 0 when the read address is 0.

Summary

You implemented the integer register file with 32 entries, ensuring proper reset logic initializes all registers to zero. You added specific guards to prevent writing to register x0 and configured read ports to always return zero when x0 is addressed. This enforces the RISC-V architectural requirement that x0 is hardwired to zero in both read and write paths.

© 2026 RtlStudio. Licensed under CC BY-NC-ND 4.0. Commercial use and modifications by third parties are not permitted.

Run it in the Verilog IDE

  1. Open the RV32I lesson in the IDE. Fetch, decode, and execute are source you can simulate.
  2. Run Verilator and watch PC, the instruction, and the register write on the waveform.
  3. Treat a program printout as done only after the ISA step this lesson names matches the wave.
  4. Change the RTL in the editor, rerun Verilator, and read the waveform again in the same tab.

The lesson is done when the simulation matches Register file with hardwired x0. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.