-
Notifications
You must be signed in to change notification settings - Fork 5
/
Controller.vhd
153 lines (132 loc) · 4.28 KB
/
Controller.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
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 20:19:14 06/25/2017
-- Design Name:
-- Module Name: Controller - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
use ieee.std_logic_unsigned.all;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity Controller is
port( clk, reset: in std_logic;
opcode: in std_logic_vector(3 downto 0);
pcSrc, pcWrite, pcWriteCond, IorD, MemWrite, IRWrite1, IRWrite2, MUXR1,
RegDST, MemToReg, RegWrite, AluSrc2, DIWrite, CZNWrite : out std_logic;
AluOp : out std_logic_vector(2 downto 0);
controlmemData : out std_logic_vector(18 downto 0);
nxtline :out std_logic_vector(3 downto 0);
cardata : out std_logic_vector(3 downto 0)
);
end Controller;
architecture behave of Controller is
component ROM1 is
port(
opcode: in std_logic_vector(3 downto 0);
lineNumber: out std_logic_vector(3 downto 0)
);
end component;
component ROM2 is
port(
opcode: in std_logic_vector(2 downto 0);
lineNumber: out std_logic_vector(3 downto 0)
);
end component;
component ControlMemory is
generic (K: integer:=19; -- number of bits per word (data size)
W: integer:=4 -- number of address bits (address size)
);
port ( clk, rst_n : std_logic;
ADDR: in std_logic_vector (W-1 downto 0); -- RAM address
DOUT: out std_logic_vector (K-1 downto 0)
); -- read data
end component;
component CAR is
port( clk, rst_n : in std_logic;
memIndex_input : in std_logic_vector(3 downto 0);
memIndex_output : out std_logic_vector(3 downto 0)
);
end component;
component mux_2bits is
Generic(W : integer :=4);
Port (D0, D1, D2, D3 : in std_logic_vector(W-1 downto 0);
S : in std_logic_vector(1 downto 0);
Y : out std_logic_vector(W-1 downto 0));
end component;
signal rom1ToMux : std_logic_vector(3 downto 0);
signal rom2ToMux : std_logic_vector(3 downto 0);
signal nextLine : std_logic_vector(3 downto 0);
signal seq : std_logic_vector(1 downto 0) := "00";
signal muxOut : std_logic_vector(3 downto 0);
signal CARout : std_logic_vector(3 downto 0);
signal controlWord : std_logic_vector(18 downto 0) := (others => '0');
signal nextlinetemp : std_logic_vector(3 downto 0);
signal zero4Signal : std_logic_vector(3 downto 0);
begin
R1: ROM1 port map(opcode, rom1ToMux);
R2: ROM2 port map(opcode(3 downto 1), rom2ToMux);
zero4signal <= "0000";
M: mux_2bits port map(zero4signal, rom1ToMux, rom2ToMux, nextLine, seq, muxOut);
C: CAR port map(clk, reset, muxOut, CARout);
cardata <= carout;
Mem: ControlMemory port map(clk, reset, CARout, controlWord);
seq <= controlWord(1 downto 0);
nextlinetemp <= CARout + "0001";
nextLine <= nextlinetemp;
nxtline <= nextline;
controlmemData <= controlword;
process (clk, reset, controlword) begin
if(reset = '0') then
pcsrc <= '0';
pcwrite <= '0';
pcwritecond <= '0';
iord <= '0';
memwrite <= '0';
irwrite1 <= '0';
irwrite2 <= '0';
muxr1 <= '0';
regdst <= '0';
memtoreg <= '0';
regwrite <= '0';
alusrc2 <= '0';
aluop <= "000";
diwrite <= '0';
cznwrite <= '0';
else
pcsrc <= controlWord(18);
pcwrite <= controlWord(17);
pcwritecond <= controlWord(16);
iord <= controlWord(15);
memwrite <= controlWord(14);
irwrite1 <= controlWord(13);
irwrite2 <= controlWord(12);
muxr1 <= controlWord(11);
regdst <= controlWord(10);
memtoreg <= controlWord(9);
regwrite <= controlWord(8);
alusrc2 <= controlWord(7);
aluop <= controlWord(6 downto 4);
diwrite <= controlWord(3);
cznwrite <= controlWord(2);
end if;
end process;
end behave;