-
Notifications
You must be signed in to change notification settings - Fork 3
/
ControlUnit.v
136 lines (115 loc) · 2.13 KB
/
ControlUnit.v
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// //
// CMPEN 331 Spring 2017 //
// Code by John Huddleston (Section 2) //
// Control unit module //
// //
//////////////////////////////////////////////////////////////////////////////////
// //
// NOTE: Not all instructions are implemented yet. Lab 4 requires only LW to //
// be defined, but I have defined control outputs for a few other //
// (simple) instructions to be prepared. //
// //
//////////////////////////////////////////////////////////////////////////////////
module ControlUnit(
input [5:0] op, func,
output reg regRt, wreg, m2reg, wmem, aluimm,
output reg [3:0] aluc
);
always @ (*) begin
// Deriving the necessary control signals, starting by identifying the opcode
case(op)
// R-format instruction
6'b000000: begin
// Deriving r-format control signals from the function codes
case(func)
// ADD
6'b100000: begin
aluc = 4'b0010;
wreg = 1;
m2reg = 0;
aluimm = 0;
regRt = 0;
wmem = 0;
end
// SUB
6'b100010: begin
aluc = 4'b0110;
wreg = 1;
m2reg = 0;
aluimm = 0;
regRt = 0;
wmem = 0;
end
// AND
6'b100100: begin
aluc = 4'b0000;
wreg = 1;
m2reg = 0;
aluimm = 0;
regRt = 0;
wmem = 0;
end
// OR
6'b100101: begin
aluc = 4'b0001;
wreg = 1;
m2reg = 0;
aluimm = 0;
regRt = 0;
wmem = 0;
end
// XOR
6'b100110: begin
aluc = 4'b0010;
wreg = 1;
m2reg = 0;
aluimm = 0;
regRt = 0;
wmem = 0;
end
// SLL
// SRL
// SRA
// JR
endcase
end
// ADDI
// ANDI
// ORI
// XORI
// LW
6'b100011: begin
aluc = 4'b0010;
wreg = 1;
m2reg = 1;
aluimm = 1;
regRt = 1;
wmem = 0;
end
// SW
6'b101011: begin
aluc = 4'b0010;
wreg = 0;
m2reg = 0;
aluimm = 1;
regRt = 1;
wmem = 1;
end
// BEQ
// BNE
// LUI
// J
// JAL
default: begin
aluc = 4'b0000;
wreg = 0;
m2reg = 0;
aluimm = 0;
regRt = 0;
wmem = 0;
end
endcase
end
endmodule