VHDL Code For The Stack System

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

LAB-14 (Sequential Circuits) Stack System

Lab Objective:Implement & Simulating the Stack System using VHDL The block diagram below shows the basic building block of a stack system:

VHDL Code for the Stack System


library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity stack is port (clock : in std_logic; M : in std_logic_vector (1 downto 0); Datain : in std_logic_vector (3 downto 0); Dataout : out std_logic_vector (3 downto 0)); end entity; architecture beh of stack is type RAM16x4 is array (0 to 15) of std_logic_vector (3 downto 0); signal RAM1:RAM16x4; signal address: integer range 0 to 15; signal state : std_logic_vector (3 downto 0):="0000"; signal full : std_logic :='0'; signal empty : std_logic :='1';

Computer Science & Engineering Department

begin process (clock) begin RAM1(0)<=x"0"; RAM1(1)<=x"1"; RAM1(2)<=x"2"; RAM1(3)<=x"3"; RAM1(4)<=x"4"; RAM1(5)<=x"5"; RAM1(6)<=x"6"; RAM1(7)<=x"7"; RAM1(8)<=x"8"; RAM1(9)<=x"9"; RAM1(10)<=x"A"; RAM1(11)<=x"B"; RAM1(12)<=x"C"; RAM1(13)<=x"D"; RAM1(14)<=x"E"; RAM1(15)<=x"F"; case M is when "01" => if full='1' then assert false report "The stack is full" ; elsif (clock'event and clock='1') then state <= state+1; end if; when "10" => if empty='1' then assert false report "The stack is empty"; elsif (clock'event and clock='1') then state <= state-1; end if; when others => state <= state; end case; end process; full <= state(0) and state(1) and state (2) and state (3); empty <= not ( state(0) or state(1) or state(2) or state (3)); address <= conv_integer(state); RAM1(address)<= datain dataout <= RAM1(address) else "ZZZZ"; end architecture; when when m="01"; m="10"

Computer Science & Engineering Department

- When the stack is full, we will get a message in the TextIO that the stack is full

Computer Science & Engineering Department

- Performing push and pop operations in the stack.

Computer Science & Engineering Department

You might also like