Problems

27. Synchronous FIFO

HardWrite the moduleAbout 35 min
fifomemorypointersflags

Build a first-in, first-out queue that holds up to 4 bytes, with one clock for both sides.

rd_data always shows the oldest entry (the one a read would remove) whenever the FIFO is not empty, with no extra cycle of delay; when it is empty, rd_data is not checked. On a rising clock edge:

  • A write (wr_en = 1) stores wr_data at the back, but only if the FIFO is not full. A write while full is ignored.
  • A read (rd_en = 1) removes the front entry, but only if the FIFO is not empty. A read while empty is ignored.
  • Both in the same cycle: each happens if its own rule allows it. So when full, only the read happens; when empty, only the write happens; otherwise both happen and the number of entries stays the same.

full is 1 when 4 entries are stored; empty is 1 when none are. rst (synchronous, active high) empties the FIFO.

Ports

Module fifo4x8

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
wr_enin1Write request.
wr_datain8Data to write.
rd_enin1Read request (removes the front entry).
rd_dataout8The front entry.
fullout14 entries stored.
emptyout1No entries stored.

Example

Write 0x11, 0x22, 0x33, 0x44: full = 1 and rd_data = 0x11. A fifth write is dropped. One read: full = 0 and rd_data = 0x22.

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

Verilogfifo4x8.v
14px
Loading the editor…

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.

Synchronous FIFO: Verilog interview question | breadboardhub