Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ641
Page ↗
Q641DVASIC interview problem

Find an associative-array value without a sentinel

TechniquesDVSystemVerilogAssociative arraySparse traversalAPI design
DifficultyMedium
TopicSystemVerilog Data Structures
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

A reference model stores int values at byte keys, and every byte value including 8'hFF is legal. Return a success flag separately from the first key whose value matches a target.

Starting declarationSystemVerilog
int mem[byte];

function bit find_value(input int target, output byte key);

Example input and output

Use this case to check your interpretation
Input
mem = '{8'hFF: 3}, target = 3
Output
success = 1, key = 8'hFF
Explanation

The all-ones key remains representable because success is carried independently rather than encoded as an impossible byte value.

02

Requirements (4)

  • Return failure cleanly for an empty associative array.
  • Visit each existing key at most once using first() and next().
  • Return the first matching key in associative index order.
  • Use the function result as the success indicator instead of reserving a key as a sentinel.