-
Notifications
You must be signed in to change notification settings - Fork 0
/
RegisterFile.vhd
69 lines (49 loc) · 1.64 KB
/
RegisterFile.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- Sub Entity Register File
-- loading libraries
library std;
use std.standard.all;
library ieee;
use ieee.std_logic_1164.all;
library ieee;
use ieee.numeric_std.all;
library std;
use std.standard.all;
-- entity declaration
entity RegisterFile is
port( add1, add2, add3 : in std_logic_vector(2 downto 0);
data3, pc: in std_logic_vector(15 downto 0);
clock, writ, writ_pc, rst: in std_logic ;
data1, data2: out std_logic_vector(15 downto 0));
end entity;
-- architecture
architecture rf of RegisterFile is
-- reg file of size 8 and each 16 bits
type regFile is array(0 to 7) of std_logic_vector(15 downto 0);
signal registers: regFile; -- signal to represent reg file
begin
process (clock) -- process on clock
begin
if((falling_edge(clock))) then
if (rst = '1') then -- reset -> all value set to zero
for i in 0 to 7 loop
registers(i) <= "0000000000000000";
end loop;
else
if (writ = '1' and writ_pc = '1') then -- reg update based on write and program counter write signals
if ((not (add3 = "111")) ) then
registers(to_integer(unsigned(add3))) <= data3;
end if;
registers(7) <= pc;
end if;
if(writ = '1' and writ_pc = '0') then
registers(to_integer(unsigned(add3))) <= data3;
end if;
end if;
end if;
end process;
process (add1, add2) -- process on address signals
begin
data1 <= registers(to_integer(unsigned(add1))); -- reading data from provided addresses
data2 <= registers(to_integer(unsigned(add2)));
end process;
end rf;