-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemory.vhdl
83 lines (73 loc) · 2.19 KB
/
Memory.vhdl
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity MEMORY is
port(CLK, WR_Enable, RW_Enable: in std_logic;
ADDR: in std_logic_vector(15 downto 0);
DATA: in std_logic_vector(15 downto 0);
OUTP: out std_logic_vector(15 downto 0)
);
end MEMORY;
architecture behav of MEMORY is
type vec_array is array(0 to 2**5 - 1) of std_logic_vector(15 downto 0);
--0111000000000010
signal RAM: vec_array:= (
0 => "0000000000000001",
1 => "1111111111111110",
2 => "0000000000000010",-- in ra rb rc
others=>(others=>'1'));
-- signal RAM: vec_array:= (others=>b"0000000000000000");
-- 00 00 000 001 002 0 00
begin
process(CLK, ADDR, RW_Enable)
variable out_t : std_logic_vector(15 downto 0) := (others => '1');
begin
if falling_edge(CLK) then
if WR_Enable = '1' then
RAM(to_integer(unsigned(ADDR))) <= DATA;
end if;
end if;
if RW_Enable = '1' then
if to_integer(unsigned(ADDR)) < 15 then
out_t := RAM(to_integer(unsigned(ADDR)));
else
out_t := (others => '0');
end if;
end if;
outp <= out_t;
end process;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity IM is
port(
CLK: in std_logic;
ADDR: in std_logic_vector(15 downto 0);
OUTP: out std_logic_vector(15 downto 0)
);
end IM;
architecture behav of IM is
type vec_array is array(0 to 2**5 - 1) of std_logic_vector(15 downto 0);
signal RAM: vec_array:= (
--0 => "0111000000001010",
0 => "0000001000000001", -- lw r1, r0, 0, load mem 0 in r1
-- 1 => "0111000001000001", -- lw r0, r0, 1, load mem 1 in r0
5 => "0111000000000001", -- lw r1, r0, 0, load mem 0 in r1
9 => "0001001000000000", -- add r0, r0, r1, add r1 and r0 and store in r0
-- 1 => "0001001011011000", -- r1, r3, r3
-- 2 => "0000000000000001", -- r0, 1
-- 3 => "0001001011111000", -- r1, r3, r7
others=>(others=>'1'));
begin
process(CLK, ADDR)
variable out_t : std_logic_vector(15 downto 0) := (others => '1');
begin
if to_integer(unsigned(ADDR)) < 15 then
out_t := RAM(to_integer(unsigned(ADDR)));
else
out_t := (others => '1');
end if;
outp <= out_t;
end process;
end architecture;