-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathControlUnit.v
More file actions
86 lines (76 loc) · 2.07 KB
/
ControlUnit.v
File metadata and controls
86 lines (76 loc) · 2.07 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
`timescale 10ns/1ns
module control_unit
// IO ports
(
input wire [6:0] opcode,
output reg [1:0] ImmSel, aluOP,
output reg reg_write_en, aluSrc, MemtoReg, MemRead, MemWrite, branch
);
// symbolic opcode representation
localparam [6:0]
R_OP = 7'b0110011,
LOAD_OP = 7'b0000011,
STORE_OP = 7'b0100011,
BEQ_OP = 7'b1100011;
//body
always @*
begin
case(opcode)
R_OP:
begin
ImmSel = 2'b00;
reg_write_en = 1'b1;
aluSrc = 1'b0;
MemtoReg = 1'b0;
aluOP = 2'b10;
MemRead = 1'b0;
MemWrite = 1'b0;
branch = 1'b0;
end
LOAD_OP:
begin
ImmSel = 2'b00;
reg_write_en = 1'b1;
aluSrc = 1'b1;
MemtoReg = 1'b1;
aluOP = 2'b00;
MemRead = 1'b1;
MemWrite = 1'b0;
branch = 1'b0;
end
STORE_OP:
begin
ImmSel = 2'b01;
reg_write_en = 1'b0;
aluSrc = 1'b1;
MemtoReg = 1'b1;
aluOP = 2'b00;
MemRead = 1'b0;
MemWrite = 1'b1;
branch = 1'b0;
end
BEQ_OP:
begin
ImmSel = 2'b10;
reg_write_en = 1'b0;
aluSrc = 1'b0;
MemtoReg = 1'b0;
aluOP = 2'b01;
MemRead = 1'b0;
MemWrite = 1'b0;
branch = 1'b1;
end
default:
begin
ImmSel = 2'b00;
reg_write_en = 1'b1;
aluSrc = 1'b1;
MemtoReg = 1'b0;
aluOP = 2'b10;
MemRead = 1'b0;
MemWrite = 1'b0;
branch = 1'b0;
end
endcase
end
endmodule