-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlUnit.v
More file actions
175 lines (165 loc) · 4.02 KB
/
ControlUnit.v
File metadata and controls
175 lines (165 loc) · 4.02 KB
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 20.07.2024 22:55:01
// Design Name:
// Module Name: ControlUnit
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module ControlUnit (
input wire [31:0] Instruction,
output reg isSt,
output reg isLd,
output reg isBeq,
output reg isBgt,
output reg isRet,
output reg isImmediate,
output reg isWb,
output reg isUBranch,
output reg isCall,
output reg isAdd,
output reg isSub,
output reg isCmp,
output reg isMul,
output reg isDiv,
output reg isMod,
output reg isLsl,
output reg isLsr,
output reg isAsr,
output reg isOr,
output reg isAnd,
output reg isNot,
output reg isMov
);
// Extracting opcode and immediate bit
wire [4:0] op_code;
wire I;
assign op_code = Instruction[31:27];
assign I = Instruction[26];
// Process to generate control signals based on opcode and immediate bit
always @(*) begin
// Default values for control signals
isSt = 0;
isLd = 0;
isBeq = 0;
isBgt = 0;
isRet = 0;
isImmediate = 0;
isWb = 0;
isUBranch = 0;
isCall = 0;
isAdd = 0;
isSub = 0;
isCmp = 0;
isMul = 0;
isDiv = 0;
isMod = 0;
isLsl = 0;
isLsr = 0;
isAsr = 0;
isOr = 0;
isAnd = 0;
isNot = 0;
isMov = 0;
// Set isImmediate if I bit is set
if (I == 1'b1) begin
isImmediate = 1;
end
// Generate control signals based on opcode
case (op_code)
5'b00000: begin // add
isAdd = 1;
isWb = 1;
end
5'b00001: begin // sub
isSub = 1;
isWb = 1;
end
5'b00010: begin // mul
isMul = 1;
isWb = 1;
end
5'b00011: begin // div
isDiv = 1;
isWb = 1;
end
5'b00100: begin // mod
isMod = 1;
isWb = 1;
end
5'b00101: begin // cmp
isCmp = 1;
end
5'b00110: begin // and
isAnd = 1;
isWb = 1;
end
5'b00111: begin // or
isOr = 1;
isWb = 1;
end
5'b01000: begin // not
isNot = 1;
isWb = 1;
end
5'b01001: begin // mov
isMov = 1;
isWb = 1;
end
5'b01010: begin // lsl
isLsl = 1;
isWb = 1;
end
5'b01011: begin // lsr
isLsr = 1;
isWb = 1;
end
5'b01100: begin // asr
isAsr = 1;
isWb = 1;
end
5'b01110: begin // ld
isLd = 1;
isWb = 1;
isAdd = 1;
end
5'b01111: begin // st
isSt = 1;
isAdd = 1;
end
5'b10000: begin // beq
isBeq = 1;
end
5'b10001: begin // bgt
isBgt = 1;
end
5'b10010: begin // b
isUBranch = 1;
end
5'b10011: begin // call
isCall = 1;
isUBranch = 1;
isWb = 1;
end
5'b10100: begin // ret
isRet = 1;
isUBranch = 1;
end
default: begin
// Default case, all control signals are 0
end
endcase
end
endmodule