27. Synchronous FIFO
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
| 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 | 8 | Data to write. |
rd_en | in | 1 | Read request (removes the front entry). |
rd_data | out | 8 | The front entry. |
full | out | 1 | 4 entries stored. |
empty | out | 1 | No 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.
Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
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.
Press Build to check your code with Yosys. Errors and warnings show here, and a clean build draws the logic diagram.
Build your design to drive it by hand and see its signals here.