RTL Studio Open IDE

3.3 · RISC-V CLASS

Store byte, half, and word alignment

Implement store data alignment logic in the RV32I Load/Store Unit to correctly place byte, half, and word data into memory lanes.

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

What you practice

Store byte, half, and word alignment (3.3). Implement store data alignment logic in the RV32I Load/Store Unit to correctly place byte, half, and word data into memory lanes. It is in Store SB/SH/SW — 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 to align store data into the correct byte lane of a 32-bit memory word. This is a critical step in the Load/Store Unit (LSU) to ensure data is written to the correct addresses for byte, half-word, and word operations.

Learning objectives

  • Understand how to shift store data based on the address offset.
  • Implement byte enable signals to select the correct memory lanes.
  • Handle misalignment detection for half-word and word accesses.
  • Complete the rv32i_lsu module to pass the testbench checks.

Theory

The Load/Store Unit must align data to the memory word boundary before writing. For a byte store, the 8-bit data must be placed in the correct byte lane (bits 7:0, 15:8, 23:16, or 31:24) based on the lower two bits of the address. The byte_en signal indicates which lanes are active. For half-word stores, the 16-bit data is aligned to either the lower or upper half of the word, and misalignment is detected if the address is odd. Word stores write the full 32-bit data to all lanes, and misalignment is detected if the address is not zero. The store_wdata output is constructed by shifting the input store_data to the correct position.

Practice

  1. Open RtlStudio and select this chapter from the Examples or Lecture list.
  2. In the Explore tree, open student/rtl/ip/riscv/rv32i_lsu.sv.
  3. Locate the always_comb block inside the rv32i_lsu module.
  4. Fill in the __TODO__ placeholders for byte_en assignments in the byte store case statement.
  5. Replace the entire __TODO__ placeholder with the correct 4-bit byte enable pattern for each address lane.
  6. Save the file and run Simulation from the sidebar.
  7. Check the Log panel for INFO: PASS.

Summary

You implemented the logic to align store data into the correct byte lane of a 32-bit memory word based on the address and size. You generated the appropriate byte enable signals to indicate which bytes are valid for writing. The verification confirmed that the implementation correctly handles byte, half-word, and word store operations.

© 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 Store byte, half, and word alignment. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.