Problems

29. FIFO with count and almost flags

HardWrite the moduleAbout 35 min
fifomemorycountersflags

Build an 8-entry, 8-bit synchronous FIFO that also reports how full it is.

The read and write rules are those of a standard FIFO: rd_data shows the oldest entry whenever the FIFO is not empty; a write (wr_en) adds wr_data at the back unless the FIFO is full; a read (rd_en) removes the front entry unless it is empty; a read and a write in the same cycle each follow their own rule, so when neither flag is set the count stays the same.

Outputs, all from the current state:

  • count: the number of entries, 0 to 8.
  • full: count is 8. empty: count is 0.
  • almost_full: count is 6 or more (two or fewer free slots), so a sender with a two-cycle reaction time can stop in time.
  • almost_empty: count is 2 or less.

rst (synchronous, active high) empties the FIFO.

Ports

Module fifo8_af

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
wr_enin1Write request.
wr_datain8Data to write.
rd_enin1Read request.
rd_dataout8The front entry.
countout4Entries stored, 0 to 8.
fullout1count is 8.
emptyout1count is 0.
almost_fullout1count is 6 or more.
almost_emptyout1count is 2 or less.

Example

After six writes: count = 6, almost_full = 1, full = 0. A read and a write in the same cycle leave count at 6.

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

Verilogfifo8_af.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.

FIFO with count and almost flags: Verilog interview question | breadboardhub