-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnidadeControl.vhd
123 lines (105 loc) · 3.05 KB
/
UnidadeControl.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
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
ENTITY UnidadeControl IS
PORT (
Clock : IN STD_LOGIC;
OpCode : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
PCWrite, RegWrite, RegAuxWrite, IRWrite, MemToReg : OUT STD_LOGIC;
AluSrcA, AluSrcB, AluControl : OUT STD_LOGIC_VECTOR (1 DOWNTO 0);
Reset : IN STD_LOGIC
);
END UnidadeControl;
ARCHITECTURE LogicFunction OF UnidadeControl IS
TYPE STATE IS (fetch, decode, exec, complete, mov, mov_i, exec_i);
SIGNAL NextStage : STATE := fetch;
BEGIN
PROCESS(Clock, OpCode, NextStage, Reset)
BEGIN
IF Reset = '1' THEN
NextStage <= fetch;
ELSIF rising_edge(Clock) THEN
CASE NextStage IS
WHEN fetch =>
PCWrite <= '1';
IRWrite <= '1';
MemToReg <= '0';
AluControl <= "10";
AluSrcA <= "11";
AluSrcB <= "10";
RegWrite <= '0';
RegAuxWrite <= '0';
--Next State
NextStage <= decode;
WHEN decode =>
PCWrite <= '0';
IRWrite <= '0';
MemToReg <= '0';
AluControl <= "00";
AluSrcA <= "00";
AluSrcB <= "00";
RegWrite <= '0';
RegAuxWrite <= '1';
--Next State
IF OpCode = "0000" THEN NextStage <= mov;
ELSIF OpCode = "0001" THEN NextStage <= mov_i;
ELSIF OpCode(0) = '0' THEN NextStage <= exec;
ELSIF OpCode(0) = '1' THEN NextStage <= exec_i;
END IF;
WHEN exec =>
PCWrite <= '0';
IRWrite <= '0';
MemToReg <= '0';
AluControl <= OpCode(2 DOWNTO 1);
AluSrcA <= "00";
AluSrcB <= "00";
RegWrite <= '0';
RegAuxWrite <= '0';
--Next State
NextStage <= complete;
WHEN exec_i =>
PCWrite <= '0';
IRWrite <= '0';
MemToReg <= '0';
AluControl <= OpCode(2 DOWNTO 1);
AluSrcA <= "00";
AluSrcB <= "01";
RegWrite <= '0';
RegAuxWrite <= '0';
NextStage <= complete;
WHEN mov =>
PCWrite <= '0';
IRWrite <= '0';
MemToReg <= '1';
AluControl <= "00";
AluSrcA <= "00";
AluSrcB <= "00";
RegWrite <= '1';
RegAuxWrite <= '0';
--Next State
NextStage <= fetch;
WHEN mov_i =>
PCWrite <= '0';
IRWrite <= '0';
RegWrite <= '0';
AluControl <= "10";
AluSrcA <= "10";
AluSrcB <= "01";
MemToReg <= '0';
RegAuxWrite <= '0';
--Next State
NextStage <= complete;
WHEN complete =>
PCWrite <= '0';
IRWrite <= '0';
MemToReg <= '0';
AluControl <= "00";
AluSrcA <= "00";
AluSrcB <= "00";
RegWrite <= '1';
RegAuxWrite <= '0';
NextStage <= fetch;
END CASE;
END IF;
END PROCESS;
END LogicFunction;