RTL Studio Open IDE

3.1 · RISC-V CLASS

Load/store control and byte enables

Implement per-byte write enable generation and data alignment logic for the RISC-V Load/Store Unit based on access size and address offset.

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

What you practice

Load/store control and byte enables (3.1). Implement per-byte write enable generation and data alignment logic for the RISC-V Load/Store Unit based on access size and address offset. It is in LSU control & byte_en — Part 3 · Load/Store & Local Memory 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 logic that generates per-byte write enables based on the access size and address offset. This logic is critical for correctly handling byte, half-word, and word memory operations in a RISC-V processor.

Learning objectives

  • Generate the correct 4-bit byte_en mask for byte, half, and word accesses.
  • Align store_wdata to the correct byte lane based on the address offset.
  • Gate the byte enables with the memwrite signal to prevent unintended writes.
  • Detect alignment violations for half-word and word accesses.

Theory

The Load/Store Unit (LSU) must translate a generic memory request into specific byte-level control signals. The mem_size input indicates whether the operation is a byte (0), half-word (1), or word (2). The addr input provides the lower bits of the address, which determine the byte offset within a 32-bit word.

For a byte access (mem_size == 2'd0), only one byte is enabled. The enabled byte corresponds to the offset in addr[1:0]. For example, addr == 2'b00 enables the least significant byte (4'b0001).

For a half-word access (mem_size == 2'd1), two adjacent bytes are enabled. The alignment check misalign = addr[0] ensures the address is even for half-word accesses. If addr[1] == 0, the lower two bytes are enabled (4'b0011). If addr[1] == 1, the upper two bytes are enabled (4'b1100).

For a word access (mem_size == 2'd2), all four bytes are enabled (4'b1111). The alignment check misalign = |addr ensures the address is word-aligned.

Practice

  1. Open RtlStudio and select this chapter from the Examples list.
  2. Navigate to the Explore panel and open student/rtl/ip/riscv/rv32i_lsu.sv and student/tb/tb_top.sv.
  3. Locate the always_comb block inside the module.
  4. Implement the byte enable mask for byte accesses (mem_size == 0) using addr[1:0].
  5. Implement the byte enable mask for half-word accesses (mem_size == 1) using addr[1].
  6. Implement the byte enable mask for word accesses (mem_size == 2) as all ones.
  7. Implement the store_wdata alignment logic for each access size.
  8. Run the simulation by clicking Simulation in the sidebar and then Run.

Summary

You implemented the logic to generate per-byte write enables based on access size and address offset within the Load/Store Unit. This practice reinforced how to map address alignment to specific byte enable masks for byte, half-word, and word operations. The key takeaway is ensuring that memory writes are precisely gated by the memwrite signal and aligned correctly to the target bytes.

© 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/store control and byte enables. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.