-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGammaStack.vhdl
More file actions
63 lines (61 loc) · 2.42 KB
/
GammaStack.vhdl
File metadata and controls
63 lines (61 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- Empty descending stack implementation in VHDL.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity GammaStack is
port (
Clk : in std_logic; -- Clock for the stack.
Reset : in std_logic; -- Active high reset.
Enable : in std_logic; -- Enable the stack. Otherwise neither push nor pop will happen.
Data_In : in std_logic_vector(31 downto 0); -- Data to be pushed to stack.
Data_Out : out std_logic_vector(31 downto 0); -- Data popped from the stack.
Push_Mode : in std_logic; -- Active low for POP and active high for PUSH.
Stack_Full : out std_logic; -- Goes high when the stack is full.
Stack_Empty : out std_logic; -- Goes high when the stack is empty.
Debug_Dump : in std_logic -- Dump the stack for debugging.
);
end GammaStack;
architecture Behavioral of GammaStack is
type stack is array (0 to 31) of std_logic_vector(31 downto 0); -- Stack of 32 elements.
signal Stack_Reg : stack; -- Signal to hold the stack.
signal Top : integer range 0 to 31 := 0; -- Top of the stack.
begin
process(Clk, Reset)
begin
-- print the entire stack
if Debug_Dump = '1' then
for i in 0 to 31 loop
if to_string(Stack_Reg(i)) /= "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU" then
report "pos: " & integer'image(i);
report "value: " & to_string(Stack_Reg(i));
end if;
end loop;
end if;
if Reset = '1' then
Top <= 0;
Stack_Empty <= '1';
Stack_Full <= '0';
elsif rising_edge(Clk) then
if Enable = '1' then
if Push_Mode = '0' then -- POP
if Top = 0 then
Stack_Empty <= '1';
else
Data_Out <= Stack_Reg(Top - 1);
Stack_Empty <= '0';
Top <= Top - 1;
end if;
else -- PUSH
if Top = 31 then
Stack_Full <= '1';
else
Stack_Full <= '0';
Stack_Empty <= '0';
Top <= Top + 1;
Stack_Reg(Top) <= Data_In;
end if;
end if;
end if;
end if;
end process;
end Behavioral;