Repository navigation
Expand file tree
/
Copy pathStack.vhd
More file actions
61 lines (50 loc) · 1.38 KB
/
Copy pathStack.vhd
File metadata and controls
61 lines (50 loc) · 1.38 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
-- Quartus II VHDL Template
-- Single port RAM with single read/write address
library ieee;
use ieee.std_logic_1164.all;
entity STACK is
generic (
DATA_WIDTH : natural := 8;
ADDR_WIDTH : natural := 5
);
port (
clk : in std_logic;
data : in std_logic_vector((DATA_WIDTH-1) downto 0);
we : in std_logic;
le : in std_logic_vector(1 downto 0);
out1 : out std_logic_vector((DATA_WIDTH -1) downto 0);
out2 : out std_logic_vector((DATA_WIDTH -1) downto 0)
);
end entity;
architecture rtl of STACK is
-- Build a 2-D array type for the RAM
subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
type memory_t is array(2**ADDR_WIDTH-1 downto 0) of word_t;
-- Declare the RAM signal.
signal ram : memory_t;
-- Register to hold the address
signal top_of_stack : natural range 0 to 2**ADDR_WIDTH-1;
signal saida1: std_logic_vector((DATA_WIDTH -1) downto 0);
signal saida2: std_logic_vector((DATA_WIDTH -1) downto 0);
begin
process(clk)
begin
if(rising_edge(clk)) then
if(we = '1') then
ram(top_of_stack) <= data;
top_of_stack <= top_of_stack + 1;
end if;
if (le(1) = '1') then
if (le(0) = '0') then
top_of_stack <= top_of_stack - 1;
elsif (le(0) = '1') then
top_of_stack <= top_of_stack - 2;
end if;
end if;
saida1 <= ram(top_of_stack-2);
saida2 <= ram(top_of_stack-1);
end if;
end process;
out1 <= saida1;
out2 <= saida2;
end rtl;