-
Notifications
You must be signed in to change notification settings - Fork 0
/
ram.vhd
40 lines (36 loc) · 1.44 KB
/
ram.vhd
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
library ieee;
use ieee.std_logic_1164.std_ulogic;
use ieee.std_logic_1164.std_ulogic_vector;
use ieee.numeric_std.all;
entity ram is
generic(
data_width : integer := 32; --width of each data word
size : integer := 5
); --2**number of data words the memory can store
port(
clk : in std_ulogic;
data_in_write_enable : in std_ulogic;
address : in std_ulogic_vector(size - 1 downto 0);
data_in : in std_ulogic_vector(data_width - 1 downto 0);
data_out : out std_ulogic_vector(data_width - 1 downto 0)
);
end entity ram;
architecture RTL of ram is
type memory is array (2**size - 1 downto 0) of std_ulogic_vector(data_width - 1 downto 0); --data type for memory
signal ram : memory; --memory array
signal internal_address : integer range 0 to 2**size - 1; --internal address register
begin
process(clk)
begin
if (clk'EVENT and clk = '1') then
if (data_in_write_enable = '1') then --write enable is asserted
ram(to_integer(unsigned(address))) <= data_in; --write input data into memory
end if;
internal_address <= to_integer(unsigned(address));
end if;
end process;
with internal_address select data_out <= --output data at the stored address
std_ulogic_vector(to_unsigned(4, data_width)) when 0,
std_ulogic_vector(to_unsigned(4, data_width)) when 1,
ram(internal_address) when others;
end architecture RTL;