Design a First-In First-Out (FIFO) buffer, also called a queue.
The FIFO receives 2-bit data items and can store up to two items. Every read and write operation must be performed in one cycle. Simultaneous read and write operations are also possible.
The write operation stores the input data (data_in) into the FIFO when @write=1@. The storage takes place at the rising edge of the clock. The read operation at the rising edge of the clock when @read=1@.
The signals empty and full indicate when the FIFO is empty or full, respectively. A read operation when empty is invalid. A write operation is invalid when the FIFO is full and no read operation occurs simultaneously. On an invalid write, the input data is ignored.
The following waveform illustrates the behavior of the FIFO. The last row reports the number of elements stored in the FIFO at each cycle.
Specification
module fifo(clk, rst, write, data_in, read, data_out, full, empty); input clk; input rst; input write; input [1:0] data_in; input read; output [1:0] data_out; output full; output empty;
Input
Output