RTL Design #20 · 2026-10-13 · Stacks · Medium · about 15 min
A stack that loses count
stack8 is an eight-entry stack, the kind a branch predictor uses to remember return addresses. top shows the newest entry still held and count the number of entries. Each cycle:
pushalone putsdinon top. It's ignored when the stack is full (count= 8).popalone removes the top entry. It's ignored when the stack is empty.pushandpoptogether replace the top entry withdin: the old top goes,dintakes its place, andcountdoesn't change. This works when the stack is full too. If the stack is empty there's nothing to replace, sodinis simply pushed.
top may be anything while the stack is empty. The current design gets pushes and pops right one at a time, but not every cycle is that simple. Fix stack.sv.
Write and run your answer in the browser. The hidden tests check it, and it’s free.