Consider a FIFO with a write pointer (wr_ptr) and a read pointer (rd_ptr) both 3 bits wide. The full flag is set when the write pointer is one position behind the read pointer in a circular buffer of size 8.
Given the following VHDL snippet, what is the value of full when wr_ptr = "110" and rd_ptr = "111"?
signal wr_ptr : std_logic_vector(2 downto 0) := "110"; signal rd_ptr : std_logic_vector(2 downto 0) := "111"; signal full : std_logic; full <= '1' when (wr_ptr = rd_ptr - 1) else '0';
Remember that subtraction on std_logic_vector is not directly supported. Consider how the pointers wrap around in a circular buffer.
The expression wr_ptr = rd_ptr - 1 is invalid because std_logic_vector does not support direct arithmetic operations. This causes a signal assignment error. Logically, if it worked, "111" (7) - 1 = 6 ("110"), so full would be '1', but the code will not compile.
In a FIFO design, the empty flag is set when the write pointer equals the read pointer.
Given the following VHDL code snippet, what is the value of empty when wr_ptr = "001" and rd_ptr = "001"?
signal wr_ptr : std_logic_vector(2 downto 0) := "001"; signal rd_ptr : std_logic_vector(2 downto 0) := "001"; signal empty : std_logic; empty <= '1' when wr_ptr = rd_ptr else '0';
Check if the pointers are equal.
The empty flag is '1' when the write and read pointers are equal, indicating the FIFO is empty. Here both pointers are "001", so empty is '1'.
Examine the following VHDL code snippet for the FIFO full flag. Identify the error that will cause incorrect full flag behavior.
signal wr_ptr : unsigned(2 downto 0); signal rd_ptr : unsigned(2 downto 0); signal full : std_logic; full <= '1' when wr_ptr = rd_ptr - 1 else '0';
Think about how pointer subtraction works in a circular buffer.
The full flag logic is correct and will work as intended. Unsigned subtraction in VHDL (from numeric_std) performs modulo 2^N arithmetic, which handles the circular wrap-around perfectly for power-of-two FIFO sizes. For rd_ptr = "000", rd_ptr - 1 = "111", correctly setting full when wr_ptr = "111".
Given the FIFO empty flag logic, which of the following VHDL assignments will cause a syntax error?
Check the equality operator syntax in VHDL.
In VHDL, the equality operator is =, not ==. Option A uses ==, which causes a syntax error.
A FIFO has 8 slots (3-bit pointers). The write pointer is at "101" (decimal 5), and the read pointer is at "011" (decimal 3). The FIFO full flag is '0' and empty flag is '0'.
How many items are currently stored in the FIFO?
Calculate the difference between write and read pointers modulo FIFO size.
The number of items in the FIFO is (unsigned(wr_ptr) - unsigned(rd_ptr)) mod 8 = (5 - 3) mod 8 = 2. The flags being '0' confirm it's neither empty (wr_ptr == rd_ptr) nor full (wr_ptr == rd_ptr - 1 mod 8).
