What you practice
Local data memory with byte writes (3.5). Implement a synchronous-write, combinational-read data RAM with byte enable signals for partial word updates. It is in Data memory (sync RAM) — 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
You will implement a synchronous-write, combinational-read data RAM that supports byte-level writes using byte enable signals. This capability is essential for efficient memory access in RISC-V processors where not all 32 bits of a word need to be updated.
Learning objectives
- Understand how byte enable signals control partial word writes in memory.
- Implement address decoding to map 32-bit addresses to 10-bit word indices.
- Construct a read mux that returns data only when the read enable signal is active.
- Verify byte-level write operations using a testbench with specific data patterns.
Theory
A byte-enable data memory allows updating specific 8-bit segments of a 32-bit word without affecting the others. The address input is typically divided into a word index and a byte offset. For a 32-bit address, bits [11:2] usually select the word index because the lower two bits indicate the byte within the word. The byte enable signal we is a 4-bit vector where each bit corresponds to one byte of the word. When we[i] is high, the corresponding byte of wdata is written to the memory at the calculated word index. If we is all zeros, no write occurs regardless of the clock edge. The read operation is typically combinational and controlled by a separate re signal. When re is low, the read data output is usually forced to zero or holds its previous value depending on the design. When re is high, the memory returns the 32-bit word stored at the word index derived from the address.
| Signal | Width | Direction | Description |
|---|---|---|---|
addr | 32 | Input | Memory address |
we | 4 | Input | Byte write enables (LSB = byte 0) |
wdata | 32 | Input | Write data |
re | 1 | Input | Read enable |
rdata | 32 | Output | Read data |
Practice
Open student/rtl/ip/riscv/rv32i_dmem.sv to implement the memory logic. You need to complete three assignments marked with __TODO__. First, calculate the word_idx by extracting bits [11:2] from the addr input. Second, complete the always_ff block to assign the correct byte slices of wdata to the memory when the corresponding we bit is high. Third, implement the combinational read logic for rdata using a ternary operator that checks re. After editing the IP file, open student/tb/tb_top.sv to review the testbench stimulus. The testbench performs a word write, a readback, a byte write, and a final readback. Run the Simulation from the left sidebar and check the Log panel for results.
Summary
You implemented a synchronous-write, combinational-read data RAM with byte-enable support for the RV32I load/store unit. The design correctly derives the word index from the address and handles selective byte writes using a 4-bit write enable vector. Verification confirmed that the module accurately reads and writes data at both word and byte granularities.
© 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 Local data memory with byte writes. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.