Problems

28. Find the bug: FIFO flags

HardFind the bugAbout 30 min
verificationfifoflagstest writing

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

Module fifo4x4

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
wr_enin1Write request.
wr_datain4Data to write.
rd_enin1Read request.
rd_dataout4The front entry.
fullout14 entries stored.
emptyout1No 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" }

Stuck? . Sign in to save your progress. You can solve the free problems without an account.

Test (JSON)test.json
14px

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.

Find the bug: FIFO flags: Verilog interview question | breadboardhub