Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Find an associative-array value without a sentinel

Hardware interview practice

Find an associative-array value without a sentinel

MediumSystemVerilog Data StructuresSystemVerilog

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.

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

int mem[byte];

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

Work through one case

Input
mem = '{8'hFF: 3}, target = 3
Expected output
success = 1, key = 8'hFF

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

What to cover

Requirements

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

Related questions

SystemVerilog Data StructuresChoose containers from testbench access patterns→Reference ModelsBuild a FIFO reference model→Reference ModelsTrack named bin hits→
asic.fyi · Learn silicon end to end.info@asic.fyi