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, andpop_okis 1 for the next cycle. On an empty stack the pop is ignored (pop_ok0). - push: if the stack is not full (after the pop),
dingoes on top, andpush_okis 1 for the next cycle. On a full stack the push is ignored (push_ok0).
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: randompush,pop,dinandgap(idle clocks before the item). Every item has at least one ofpushandpopset. Make all three operations (push alone, pop alone, both) common, pushes a little more than pops so the stack fills up, constraingapto 0 to 5, and make sure long gaps (3 or more) and back-to-back items (gap 0) both happen often.stk_seq: sendscountrandom items.stk_driver: waits out reset, waitsgapclocks, then drivespush,popanddinfor exactly one clock, and returns both control pins to 0. Withgap0, 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 comparepush_ok,pop_okandcountwith the model, anddoutwhenever a pop happened. Count items incheckedand mismatches inerrors; report the first few withuvm_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.