28. Find the bug: FIFO flags
Write a test that passes the correct design and fails every buggy version.
The spec: a synchronous FIFO that holds up to 4 entries of 4 bits.
- rd_data shows the oldest entry whenever the FIFO is not empty (do not check it when empty).
- On a rising clock edge, a write (wr_en = 1) adds wr_data at the back unless the FIFO is full; a read (rd_en = 1) removes the front entry unless it is empty. A read and a write in the same cycle each follow their own rule: when full only the read happens, when empty only the write happens.
- full is 1 when 4 entries are stored and empty is 1 when none are, both reflecting the state right after the last edge (no extra delay).
- rst (synchronous, active high) empties the FIFO. Registers start unknown, so begin with a reset.
Ports
| Port | Dir | Bits | What it is |
|---|---|---|---|
clk | in | 1 | Clock. |
rst | in | 1 | Synchronous reset, active high. |
wr_en | in | 1 | Write request. |
wr_data | in | 4 | Data to write. |
rd_en | in | 1 | Read request. |
rd_data | out | 4 | The front entry. |
full | out | 1 | 4 entries stored. |
empty | out | 1 | No entries stored. |
Example
Write 1, 2, 3, 4: full = 1 right after the fourth edge. Write 5: ignored, and rd_data is still 1.
Writing the test
The test is a table of steps, as on the Verilog playground. Each step can set inputs, tick the clock (clk) a number of times, then check outputs. Inputs start at 0 and registers start unknown, so begin with a reset. It must pass the correct design and fail all 5 buggy versions.
{ "set": { "rst": 0, "en": 1 }, "tick": 3, "expect": { "count": 3 }, "note": "counts up" }Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
1 step, 0 with checks.
Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.