RTL Studio Open IDE

1.2 · RISC-V CLASS

Instruction memory read port

Implement a word-aligned read port for instruction memory by converting byte addresses to word indices and reading from the memory array.

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

What you practice

Instruction memory read port (1.2). Implement a word-aligned read port for instruction memory by converting byte addresses to word indices and reading from the memory array. It is in Instruction memory port — Part 1 · Fetch & Decode 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 learn how to implement a word-aligned read port for instruction memory. This is the first step in fetching instructions from a ROM or cache in a RISC-V core.

Learning objectives

  • Convert byte addresses to word indices by dropping the two least significant bits.
  • Read data from a memory array using the calculated word index.
  • Verify the instruction fetch logic using a testbench with known instruction patterns.

Theory

Instruction memory in RISC-V is byte-addressable. Each instruction is 32 bits (4 bytes) long. To access an instruction, you must convert the byte address into a word index. This is done by dividing the address by 4. In binary, dividing by 4 is equivalent to shifting right by 2 bits. This operation drops the two least significant bits (LSBs) of the address. The remaining upper bits represent the index into the memory array. The memory array stores 32-bit words. Reading from the memory array at the calculated index returns the instruction word. This logic is purely combinational. It does not require a clock signal. The address is converted to a word index. The word index is used to read the instruction. The instruction is output on the read data port.

Practice

Open RtlStudio and select this chapter. The files appear in the Explore tree. Open student/rtl/ip/riscv/rv32i_imem.sv. Locate the assign word_idx statement. Replace __TODO__[0] with the expression addr[11:2]. Locate the assign rdata statement. Replace __TODO__[0] with the expression mem[word_idx]. Open student/tb/tb_top.sv. This testbench loads two instructions into the memory. It drives addresses and checks the output. Run Simulation from the sidebar. Check the Log panel for the results.

Summary

You implemented the combinational read logic for the instruction memory using a word-aligned address index. This exercise demonstrated how to correctly shift byte addresses to access 32-bit instruction words in a single-cycle core.

© 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 Instruction memory read port. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.