RTL Studio Open IDE

0.2 · RISC-V CLASS

Load an instruction word and read it back

Preload an instruction word into the instruction memory and verify that the design reads it back correctly.

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

What you practice

Load an instruction word and read it back (0.2). Preload an instruction word into the instruction memory and verify that the design reads it back correctly. It is in $readmemh and first ADD — Part 0 · RV Core Warming Up 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

You will preload an instruction word into the instruction memory and verify that the design reads it back correctly. This step establishes the basic data path between the testbench and the instruction memory module. Understanding how to initialize and read from memory is fundamental for any CPU verification environment.

Learning objectives

  • Initialize the instruction memory array with a specific RISC-V instruction.
  • Drive an address to the instruction memory and observe the returned data.
  • Verify that the read data matches the expected instruction word.

Theory

The instruction memory (rv32i_imem) is a simple word-addressed ROM. It maps a 32-bit address to a 32-bit instruction word. The memory array is indexed by dropping the two least significant bits of the address, which represent byte offsets within a word. The testbench directly manipulates the memory array via hierarchical paths to preload instructions. This avoids the need for external files during this warm-up phase. The design simply passes the address to the memory module and returns the data on the rdata port.

Practice

  1. Open RtlStudio and select this chapter from the Examples list.
  2. Confirm that student/rtl/design.sv and student/tb/tb_top.sv appear in the Explore panel.
  3. Open student/tb/tb_top.sv in the editor.
  4. Locate the line that assigns dut_i.u_imem.mem[0].
  5. Replace the __TODO__ placeholder with the hex value for ADDI x1, x0, 5.
  6. Save the file.
  7. Click Simulation in the left sidebar and then Run.
  8. Check the Log panel for the INFO: messages and PASS status.

Summary

You successfully preloaded the instruction ROM with an ADDI opcode and verified the fetch mechanism from the testbench. This exercise reinforced the critical concept of word-aligned addressing by indexing memory with shifted addresses rather than raw byte offsets. The simulation confirmed that the design correctly retrieves the expected instruction words on the rdata port.

© 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 Load an instruction word and read it back. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.