-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPC.vhd
276 lines (234 loc) · 4.88 KB
/
PC.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
library ieee;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity PC is
port(
clk : in std_logic;
reset : in std_logic;
comp1 : in std_logic;
comp2 : in std_logic;
comp3 : in std_logic;
enReg1 : out std_logic;
enReg2 : out std_logic;
enReg3 : out std_logic;
enReg4 : out std_logic;
enComp1 : out std_logic;
enComp2 : out std_logic;
enComp3 : out std_logic;
selReg1 : out std_logic_vector (1 downto 0);
selReg2 : out std_logic_vector (1 downto 0);
selReg3 : out std_logic_vector (1 downto 0);
selReg4 : out std_logic_vector (1 downto 0);
selComp : out std_logic
);
end entity;
architecture rtl of PC is
-- Build an enumerated type for the state machine
type state_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10);
-- Register to hold the current state
signal state : state_type;
signal cont : std_logic_vector (1 downto 0);
--signal c : std_logic_vector(3 downto 0);
begin
-- Logic to advance to the next state
process (clk, reset)
begin
if reset = '1' then
state <= s0;
elsif (rising_edge(clk)) then
case state is
when s0=>
state <= s1;
when s1=>
state <= s10;
when s10=>
state <= s2;
when s2=>
if comp1 = '0' then
state <= s3;
else
state <= s4;
end if;
when s3=>
state <= s4;
when s4=>
if comp2 = '0' then
state <= s5;
else
state <= s6;
end if;
when s5=>
state <= s6;
when s6=>
if comp3 = '0' then
state <= s7;
else
state <= s8;
end if;
when s7=>
state <= s8;
when s8=>
if cont = "11" then
state <= s9;
elsif cont < "11" then
state <= s10;
end if;
when s9=>
state <= s9;
end case;
end if;
end process;
-- Output depends solely on the current state
process (state)
begin
case state is
when s0 =>
SelReg1 <= "00";
SelReg2 <= "00";
SelReg3 <= "00";
SelReg4 <= "00";
enReg1 <= '0';
enReg2 <= '0';
enReg3 <= '0';
enReg4 <= '0';
enComp1 <= '0';
enComp2 <= '0';
enComp3 <= '0';
cont <= "00";
selComp <= '0';
when s1 =>
SelReg1 <= "00";
SelReg2 <= "00";
SelReg3 <= "00";
SelReg4 <= "00";
enReg1 <= '1';
enReg2 <= '1';
enReg3 <= '1';
enReg4 <= '1';
enComp1 <= '0';
enComp2 <= '0';
enComp3 <= '0';
selComp <= '0';
when s10 =>
SelReg1 <= "00";
SelReg2 <= "00";
SelReg3 <= "00";
SelReg4 <= "00";
enReg1 <= '0';
enReg2 <= '0';
enReg3 <= '0';
enReg4 <= '0';
enComp1 <= '1';
enComp2 <= '1';
enComp3 <= '1';
selComp <= '1';
when s2 =>
SelReg1 <= "00";
SelReg2 <= "00";
SelReg3 <= "00";
SelReg4 <= "00";
enReg1 <= '0';
enReg2 <= '0';
enReg3 <= '0';
enReg4 <= '0';
enComp1 <= '1';
enComp2 <= '0';
enComp3 <= '0';
selComp <= '0';
when s3 =>
SelReg1 <= "01";
SelReg2 <= "01";
SelReg3 <= "00";
SelReg4 <= "00";
enReg1 <= '1';
enReg2 <= '1';
enReg3 <= '0';
enReg4 <= '0';
enComp1 <= '0';
enComp2 <= '0';
enComp3 <= '0';
selComp <= '0';
when s4 =>
SelReg1 <= "00";
SelReg2 <= "00";
SelReg3 <= "00";
SelReg4 <= "00";
enReg1 <= '0';
enReg2 <= '0';
enReg3 <= '0';
enReg4 <= '0';
enComp1 <= '0';
enComp2 <= '0';
enComp3 <= '0';
selComp <= '0';
when s5 =>
SelReg1 <= "00";
SelReg2 <= "10";
SelReg3 <= "01";
SelReg4 <= "00";
enReg1 <= '0';
enReg2 <= '1';
enReg3 <= '1';
enReg4 <= '0';
enComp1 <= '0';
enComp2 <= '0';
enComp3 <= '0';
selComp <= '0';
when s6 =>
SelReg1 <= "00";
SelReg2 <= "00";
SelReg3 <= "00";
SelReg4 <= "00";
enReg1 <= '0';
enReg2 <= '0';
enReg3 <= '0';
enReg4 <= '0';
enComp1 <= '0';
enComp2 <= '0';
enComp3 <= '1';
selComp <= '0';
when s7 =>
SelReg1 <= "00";
SelReg2 <= "00";
SelReg3 <= "10";
SelReg4 <= "01";
enReg1 <= '0';
enReg2 <= '0';
enReg3 <= '1';
enReg4 <= '1';
enComp1 <= '0';
enComp2 <= '0';
enComp3 <= '0';
selComp <= '0';
when s8 =>
SelReg1 <= "00";
SelReg2 <= "00";
SelReg3 <= "00";
SelReg4 <= "00";
enReg1 <= '0';
enReg2 <= '0';
enReg3 <= '0';
enReg4 <= '0';
enComp1 <= '0';
enComp2 <= '0';
enComp3 <= '0';
cont <= cont + '1';
selComp <= '0';
when s9 =>
SelReg1 <= "00";
SelReg2 <= "00";
SelReg3 <= "00";
SelReg4 <= "00";
enReg1 <= '0';
enReg2 <= '0';
enReg3 <= '0';
enReg4 <= '0';
enComp1 <= '0';
enComp2 <= '0';
enComp3 <= '0';
cont <= "00";
selComp <= '0';
end case;
end process;
end rtl;