Implementation of Stack in VHDL

Share Embed Donate


Short Description

Download Implementation of Stack in VHDL...

Description

Implementation of stack in VHDL I have been getting some requests for a Stack implementation in VHDL. This article is for all those readers. A stack is simply a Last In First Out(LIFO) memory structure. Every stack has a stack pointer(SP) which acts as an address for accessing the elements. But normally the user of the stack is not concerned with the absolute address of the stack, he is only concerned with the PUSH and POP instructions. I am not going into theory of stack in detail, but for some som e basics check the wikipedia stack page.. page There are basically 4 types of stacks: 1. Empty descending - Stack pointer(SP) points to the address where you can push the latest data. And after pushing the data, stack pointer(SP) is reduced by one till it becomes b ecomes zero. Stack grows downwards here. 2. Empty ascending - Same as type (1) , but stack grows upwards here. After the PUSH P USH operation, SP is incremented by one. 3. Fully descending - SP points to the last data which is pushed.Stack grows downward. 4. Fully ascending - SP points to the last data which is pushed, but stack grows upward here. Out of the above 4 types I have implemented the first type, Empty descending in VHDL. The depth of the stack is 256 and width is 16 bits. bits . That means using a single PUSH or POP operation you can only store or retrieve a maximum of 16 bits. Also the maximum number of elements which can be stored in the stack are 256. Of course, with a sm all edit you can change the width and depth of the stack. Check out the code below:

IEEE; ; library IEEE use IEEE IEEE. .STD_LOGIC_1164 STD_LOGIC_1164. . ALL; entity stack is Clk : in std_logic std_logic; ; --Clock for the stack.  port( Enable : in std_logic std_logic; ; --Enable the stack. Otherwise neither push nor pop will happen. Data_In : in std_logic_vector std_logic_vector( (15 downto 0); --Data to be pushed to stack Data_Out : out std_logic_vector std_logic_vector( (15 downto 0); --Data popped from the stack. PUSH_barPOP : in std_logic std_logic; ; --active low for POP and active high for PUSH. Stack_Full : out std_logic std_logic; ; --Goes high when the stack is full. Stack_Empty : out std_logic --Goes high when the stack is empty. ); stack; ; end  stack architecture Behavioral of stack is

std_logic_vector( (15 downto type mem_type is array (255 downto 0) of std_logic_vector

0); signal stack_mem : mem_type := (others => (others => '0')); signal stack_ptr : integer := 255; signal full,empty : std_logic := '0';  begin

Stack_Full
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF