What you practice
Load data sign and zero extension (3.2). Implement byte enable signals for sign and zero extension in the RV32I Load/Store Unit. It is in Load + sign extension — 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 for sign and zero extension in the RV32I Load/Store Unit. This logic ensures that narrow memory loads (bytes and half-words) are correctly widened to 32 bits for the rest of the processor pipeline.
Learning objectives
- Implement byte-level
byte_ensignals for all four possible address alignments. - Understand the difference between signed (
LB) and unsigned (LBU) extension. - Verify that the testbench passes with correct hex values for load operations.
Theory
The Load/Store Unit (LSU) must handle memory accesses that are smaller than 32 bits. When the CPU loads a byte or half-word, the data must be extended to fill the full 32-bit register. Zero extension (LBU, LHU) fills the upper bits with zeros. Sign extension (LB, LH) copies the most significant bit of the loaded data into the upper bits. The byte_en signal tells the memory interface which byte lanes of the 32-bit data bus are active for the current access. For example, a byte load at address 0 uses only the lowest byte lane, so byte_en is 4'b0001.
Practice
- Open RtlStudio and select this chapter in the Examples list.
- Confirm that
student/rtl/ip/riscv/rv32i_lsu.svappears in the Explore tree. - Open
student/rtl/ip/riscv/rv32i_lsu.svin the editor. - Locate the
byte_enassignments inside themem_sizecase statement. - Replace each
__TODO__[0]with the correct 4-bit byte enable mask for the corresponding address. - Save the file and run Simulation from the left sidebar.
- Check the Log panel for
INFO: PASS.
Summary
You implemented the byte enable logic to correctly select 8-bit data slices from the 32-bit memory word based on address alignment. You applied sign extension for signed loads and zero extension for unsigned loads to ensure proper 32-bit register updates. This exercise reinforced the critical role of the Load/Store Unit in handling variable-width data transfers.
© 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 Load data sign and zero extension. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.