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_lsumodule 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
- Open RtlStudio and select this chapter from the Examples or Lecture list.
- In the Explore tree, open
student/rtl/ip/riscv/rv32i_lsu.sv. - Locate the
always_combblock inside therv32i_lsumodule. - Fill in the
__TODO__placeholders forbyte_enassignments in the byte store case statement. - Replace the entire
__TODO__placeholder with the correct 4-bit byte enable pattern for each address lane. - Save the file and run Simulation from the sidebar.
- 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
- Open the RV32I lesson in the IDE. Fetch, decode, and execute are source you can simulate.
- Run Verilator and watch PC, the instruction, and the register write on the waveform.
- Treat a program printout as done only after the ISA step this lesson names matches the wave.
- 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.