Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Forbid consecutive POP commands

Hardware interview practice

Forbid consecutive POP commands

EasyConstraintsSystemVerilog

Randomize a 20-command PUSH/POP sequence that never contains two adjacent POP commands.

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 →
Reviewed example

Work through one case

Input
randomize exactly 20 commands, each PUSH or POP
Expected output
One valid result: [POP,PUSH,POP,PUSH,PUSH,POP,PUSH,POP,PUSH,PUSH,POP,PUSH,POP,PUSH,PUSH,POP,PUSH,POP,PUSH,POP]

The first command may be POP, all entries use the two legal enum values, and no POP directly follows another POP.

What to cover

Requirements

  1. Allow either command at index 0.
  2. Check every later element against its predecessor.
  3. Do not procedurally repair the randomized sequence.
Continue practicing

Related questions

ConstraintsConstrain unique increasing addresses→
asic.fyi · Learn silicon end to end.info@asic.fyi