Hardware interview practice
Build one-write/two-read memory from BRAM
Two identical synchronous 1W1R BRAMs must implement a logical memory with one write and two independent reads. Implement the mirrored SystemVerilog wrapper with defined collision behavior.
Starting point
Question code
input logic clk, we; input logic [7:0] waddr, raddr0, raddr1;
input logic [31:0] wdata;
output logic [31:0] rdata0, rdata1;Reviewed example
Work through one case
Input
Write address 5 with 32'h0000_00AA, then issue reads of address 5 on both read ports.Expected output
One edge after the reads, rdata0=rdata1=32'h0000_00AA.The write is mirrored into both BRAM copies, and each registered read port retrieves the same defined logical location.
What to cover
Requirements
- Instantiate or infer two 256x32 1W1R memories and apply every write to both copies on the same rising edge.
- Use copy 0 for read address raddr0 and copy 1 for raddr1; both read outputs are registered with one-cycle latency.
- Define same-edge read/write to the same address as write-first, returning wdata on the matching read output.
- There is no reset for memory contents or read data; the testbench compares read outputs only after a defined location is written.
