Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/Model sparse banked memory with packed keys

Q117·Free·SystemVerilog

Model sparse banked memory with packed keys

Difficulty
Medium
Topic
Reference Models
Language
SV
Interview prompt

Question

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.

Candidate starting point

Implementation scaffold

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

bit [31:0] mem[addr_t];

  function automatic void model_write(addr_t addr, bit [31:0] data);
    // TODO: write the exact key.
  endfunction
  function automatic bit [31:0] model_read(addr_t addr, output bit uninitialized_read);
    // TODO: return data and presence status.
  endfunction
  function automatic void model_reset();
    // TODO: flush modeled entries.
  endfunction
endmodule
Reviewed example

Trace 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.
Exact question handoffPractice Q117

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessEach time you open this Solution, one Practice Credit is used; it is not permanently unlocked. Premium Solution content also uses one credit per opening.
Continue learning

Verification Planning and Models

Review plan structure, stimulus, checkers, reference models, and system-level answers.

  • Reference Models
  • SystemVerilog
  • Associative array
  • Sparse memory
Verification Planning and Models →
Continue practicing

Related questions

Q599 · Reference ModelsBuild a FIFO reference modelMediumP→Q251 · Reference ModelsVerify a decimal palindrome checkerMediumP→
ASIC.FYI · Learn silicon end to end.info@asic.fyi