-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol.vhd
188 lines (148 loc) · 3.41 KB
/
control.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
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE WORK.cpu_lib.ALL;
entity control is
port(clock:in std_logic;
reset:in std_logic;
--keyboard input
instrReg:in bit8;
compout:in std_logic;
ready:in std_logic;
progCntrWr:out std_logic;
addrRegWr:out std_logic;
addrRegRd:out std_logic;
outRegWr:out std_logic;
outRegRd:out std_logic;
--shiftSel:out shift_type;
aluSel:out alu_type;
--compSel:out comp_type;
opRegRd:out std_logic;
opRegWr:out std_logic;
instrWr:out std_logic;
regSel:buffer reg_type;
outsel:out std_logic;
regRd:out std_logic;
regWr:out std_logic;
rw:out std_logic;
vma:out std_logic
);
end control;
architecture rtl of control is
signal current_state, next_state:state;
begin
nxtstateproc:process(current_state, instrReg, compout, ready)
begin
--progCntrWr <= '0';
--progCntrRd <= '0';
addrRegWr <= '0';
outRegWr <= '0';
outRegRd <= '0';
outsel <= '0';
--next_state <= execute;
--shiftSel <= shiftpass;
aluSel <= "0000";
--compSel <= eq;
opRegRd <= '0';
opRegWr <= '0';
instrWr <= '0';
--if regSel = "XXX" then
--regSel <= "000";
--end if;
regRd <= '0';
regWr <= '0';
rw <= '0';
vma <= '0';
case current_state is
when execute =>
case instrReg(7 downto 4) is
--null op
when "0000" =>
next_state <= incPc;
--load op
when "0001" =>
regWr <= '1';
next_state <= load1;
--add op
when "0010" =>
next_state <= add1;
when "0011" =>
next_state <= sub1;
when others =>
next_state <= incPc;
end case;
when load1 =>
regRd <= '0';
regWr <= '1';
OpRegWr <= '1';
regSel <= instrReg(1 downto 0);
next_state <= load2;
when load2 =>
regRd <= '0';
regWr <= '1';
OpRegWr <= '1';
regSel <= instrReg(1 downto 0);
next_state <= move1;
when move1 =>
regRd <= '1';
regWr <= '0';
next_state <= move2;
when move2 =>
regRd <= '1';
regWr <= '0';
next_state <= incPc;
when move3 =>
regRd <= '1';
regWr <= '0';
outsel <= '1';
next_state <= move4;
when move4 =>
regRd <= '1';
regWr <= '0';
outsel <= '1';
next_state <= move5;
when move5 =>
outSel <= '0';
next_state <= incPc;
when add1 =>
OpRegWr <= '0';
aluSel <= alu_add;
--outSel <=
regRd <= '0';
regWr <= '1';
regSel <= instrReg(1 downto 0);
next_state <= add2;
when add2 =>
OpRegWr <= '0';
aluSel <= alu_add;
regRd <= '0';
regWr <= '1';
regSel <= instrReg(1 downto 0);
next_state <= move3;
when sub1 =>
OpRegWr <= '0';
aluSel <= alu_add;
regRd <= '0';
regWr <= '1';
regSel <= instrReg(1 downto 0);
next_state <= sub2;
when sub2 =>
OpRegWr <= '0';
aluSel <= alu_add;
regRd <= '0';
regWr <= '1';
regSel <= instrReg(1 downto 0);
next_state <= move1;
when incPc =>
regSel <= regSel;
outsel <= '0';
end case;
end process;
controlproc:process(reset,next_state,clock)
begin
if reset = '0' then
current_state <= execute;
elsif clock'event and clock = '1' then
current_state <= next_state;
end if;
end process;
end rtl;