Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Model sparse banked memory with packed keys

Hardware interview practice

Model sparse banked memory with packed keys

MediumReference ModelsSystemVerilog

Build a sparse SystemVerilog memory model addressed by an 8-bit bank and a 16-bit byte offset. Reads must distinguish an unwritten location from a location explicitly written with zero.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

typedef struct packed {
  bit [7:0]  bank;
  bit [15:0] offset;
} addr_t;

bit [31:0] mem[addr_t];
Reviewed example

Work through one case

Input
write address '{bank:8'h02, offset:16'h0010} with 32'h0000_CAFE, then read the same address
Expected output
data = 32'h0000_CAFE, uninitialized_read = 0

The packed struct forms one stable integral key, so the later lookup finds exactly the previously written bank-and-offset pair.

What to cover

Requirements

  1. Store every valid write at the exact packed address key.
  2. Check exists() before indexing on a read.
  3. Return zero and assert uninitialized_read for an unwritten address.
  4. Delete all associative-array entries on reset or model flush.
Continue practicing

Related questions

Reference ModelsBuild a FIFO reference model→Reference ModelsVerify a decimal palindrome checker→Reference ModelsVerify duplicate token supply→
asic.fyi · Learn silicon end to end.info@asic.fyi