Verification #59 · 2026-11-21 · Scoreboard with simultaneous push and pop · Medium · about 30 min

Build the testbench for a four-deep stack

stk.sv is a stack (last in, first out) of four 8-bit words. On any clock edge where push and/or pop is 1, it does the pop first, then the push:

  • pop: if the stack is not empty, the top word is removed and appears on dout, and pop_ok is 1 for the next cycle. On an empty stack the pop is ignored (pop_ok 0).
  • push: if the stack is not full (after the pop), din goes on top, and push_ok is 1 for the next cycle. On a full stack the push is ignored (push_ok 0).

So a push and a pop together on a non-empty stack return the old top and put din in its place, even when the stack was full. push_ok, pop_ok, dout and count (the number of words stored) are registered: they show the result of the previous edge. dout only means something when pop_ok is 1.

Write the verification components in components.sv. The monitor and environment in env.sv are provided, and they use your four classes by name:

  • stk_item: random push, pop, din and gap (idle clocks before the item). Every item has at least one of push and pop set. Make all three operations (push alone, pop alone, both) common, pushes a little more than pops so the stack fills up, constrain gap to 0 to 5, and make sure long gaps (3 or more) and back-to-back items (gap 0) both happen often.
  • stk_seq: sends count random items.
  • stk_driver: waits out reset, waits gap clocks, then drives push, pop and din for exactly one clock, and returns both control pins to 0. With gap 0, the next item follows on the very next clock.
  • stk_scoreboard: for each item the monitor reports, in order, apply it to a model of the stack, then compare push_ok, pop_ok and count with the model, and dout whenever a pop happened. Count items in checked and mismatches in errors; report the first few with uvm_error. The monitor fills in the result fields (push_ok, pop_ok, dout, count) of the item from the pins, one clock after the operation.

Run uses tb.sv: 50 random items into the correct stack. Submit runs your testbench against the correct stack and five faulty ones. Your scoreboard must stay quiet on the first and catch each of the others.

Write and run your answer in the browser. The hidden tests check it, and it’s free.