Q120FreeSystemVerilog
Build a behavioral synchronous FIFO model
Interview prompt
Question
Implement a bounded behavioral model of a synchronous hardware FIFO that tracks occupancy and read/write pointer movement and reports illegal pushes or pops.
Starting point
Question code
class FifoModel;
function new(int depth);
function bit push();
function bit pop();
function bit push_and_pop();
function int occupancy();
function bit is_full();
function bit is_empty();
endclassReviewed example
Trace one case
Input
DEPTH=2; while empty call push_and_pop(); call push(); call push(); while nonempty call push_and_pop()Expected output
empty bypass succeeds with count=0 and both pointers unchanged; two pushes produce count=2/full; final simultaneous operation keeps count=2 and advances both pointers onceThe behavioral model tracks only occupancy and pointer movement, distinguishing an empty bypass from a simultaneous operation on stored entries.
What to cover
Requirements
- Require a fixed positive depth.
- Reject a push on full and a pop on empty.
- Track occupancy, write pointer, and read pointer.
- Expose full and empty state.
- Support one simultaneous push and pop with unchanged occupancy.
- Treat simultaneous push and pop on empty as a legal same-cycle bypass with no stored entry or pointer movement.

