-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_path.vhd
More file actions
161 lines (135 loc) · 3.59 KB
/
data_path.vhd
File metadata and controls
161 lines (135 loc) · 3.59 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.NUMERIC_STD.ALL;
entity data_path is
port(
clock : in std_logic;
reset : in std_logic;
IR_Load : in std_logic;
IR : out std_logic_vector(7 downto 0);
MAR_Load: in std_logic;
PC_Load : in std_logic;
PC_Inc : in std_logic;
A_Load : in std_logic;
B_Load : in std_logic;
ALU_Sel : in std_logic_vector(2 downto 0);
CCR_Result: out std_logic_vector(3 downto 0);
CCR_Load : in std_logic;
Bus2_Sel : in std_logic_vector(1 downto 0);
Bus1_Sel : in std_logic_vector(1 downto 0);
from_memory : in std_logic_vector(7 downto 0):= "00000000";
to_memory : out std_logic_vector(7 downto 0);
address : out std_logic_vector(7 downto 0)
);
end entity;
architecture data_path_arch of data_path is
component alu
port(
A,B : in std_logic_vector(7 downto 0);
ALU_Sel : in std_logic_vector(2 downto 0);
NZVC : out std_logic_vector(3 downto 0);
ALU_Result : out std_logic_vector(7 downto 0)
);
end component;
signal BUS2 : std_logic_vector(7 downto 0):= "00000000";
signal BUS1 : std_logic_vector(7 downto 0):= "00000000";
signal A : std_logic_vector(7 downto 0):= "00000000";
signal B : std_logic_vector(7 downto 0):= "00000000";
signal PC : std_logic_vector(7 downto 0):= "00000000";
signal MAR : std_logic_vector(7 downto 0):= "00000000";
signal NZVC : std_logic_vector(3 downto 0):= "0000";
signal ALU_Result : std_logic_vector(7 downto 0):= "00000000";
signal PC_uns : unsigned(7 downto 0):= "00000000";
begin
ALU_1 : alu port map(
A => A,
B => B,
ALU_Sel => ALU_Sel,
NZVC => NZVC,
ALU_Result => ALU_Result
);
MUX_BUS1: process(Bus1_Sel,PC,A,B)
begin
case(Bus1_Sel)is
when"00" => Bus1 <= PC;
when"01" => Bus1 <= A;
when"10" => Bus1 <= B;
when others => Bus1 <= x"00";
end case;
end process;
MUX_BUS2: process(Bus2_Sel,ALU_Result,Bus1,from_memory)
begin
case(Bus2_Sel)is
when"00" => Bus2 <= ALU_Result;
when"01" => Bus2 <= Bus1;
when"10" => Bus2 <= from_memory;
when others => Bus2 <= x"00";
end case;
end process;
address <= MAR;
to_memory<=Bus1;
-- REGISTERS -----------------------------
Instruction_Register : process(clock, reset)
begin
if(reset = '0') then
IR <= x"00";
elsif(rising_edge(clock)) then
if(IR_Load = '1') then
IR <= Bus2;
end if;
end if;
end process;
Memory_Address_Register : process(clock, reset)
begin
if(reset = '0') then
MAR <= x"00";
elsif(rising_edge(clock)) then
if(MAR_Load = '1') then
MAR <= Bus2;
end if;
end if;
end process;
Program_Counter_Register : process(clock, reset)
begin
if(reset = '0') then
PC_uns <= x"00";
elsif(rising_edge(clock)) then
if(PC_Load = '1') then
PC_uns <= unsigned(Bus2);
elsif(PC_inc = '1')then
PC_uns <= PC_uns + 1;
end if;
end if;
end process;
PC <= std_logic_vector(PC_uns);
A_Register : process(clock, reset)
begin
if(reset = '0') then
A <= x"00";
elsif(rising_edge(clock)) then
if(A_Load = '1') then
A <= Bus2;
end if;
end if;
end process;
B_Register : process(clock, reset)
begin
if(reset = '0') then
B <= x"00";
elsif(rising_edge(clock)) then
if(B_Load = '1') then
B <= Bus2;
end if;
end if;
end process;
Condition_Code_Register : process(clock, reset)
begin
if(reset = '0') then
CCR_Result <= x"0";
elsif(rising_edge(clock)) then
if(CCR_Load = '1') then
CCR_Result <= NZVC;
end if;
end if;
end process;
end architecture;