forked from ZIKOAR/32-bit-processor-with-vhdl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemoire_registres.vhd
52 lines (40 loc) · 1.41 KB
/
Memoire_registres.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
41
42
43
44
45
46
47
48
49
50
51
52
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity Memoire_registres is
port (
clk: in std_logic;
reset: in std_logic;
write_bit,read_bit: in std_logic;
read_reg_1, read_reg_2, write_reg: in std_logic_vector(4 downto 0);
write_data: in std_logic_vector(31 downto 0);
read_data_1, read_data_2: out std_logic_vector(31 downto 0)
);
end Memoire_registres;
architecture beh of Memoire_registres is
type mem_tab is array(0 to 31) of STD_LOGIC_VECTOR (31 downto 0);
signal my_mem: mem_tab := (others => (others => '0'));
begin
process(clk, reset)
variable num_edge: integer:= 0;
begin
if reset = '1' then
for i in 0 to 31 loop
my_mem(i) <= (others => '0');
end loop;
elsif rising_edge(clk) then
if (num_edge mod 5 = 4) then
if write_bit = '1' and to_integer(unsigned(write_reg)) < 31 then
my_mem(to_integer(unsigned(write_reg))) <= write_data;
end if;
end if;
if (num_edge mod 5 = 1) then
if read_bit = '1' then
read_data_1 <= my_mem(to_integer(unsigned(read_reg_1)));
read_data_2 <= my_mem(to_integer(unsigned(read_reg_2)));
end if;
end if;
num_edge := num_edge + 1;
end if;
end process;
end beh;