-
Notifications
You must be signed in to change notification settings - Fork 0
/
controlUnit.v
109 lines (100 loc) · 2.2 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
module controlUnit (instruction,regDst,branch,memRead,memToReg,ALUOp,memWrite,ALUSrc,regWrite);
input [5:0] instruction;
output regDst,branch,memRead,memToReg,memWrite,ALUSrc,regWrite;
output [2:0] ALUOp;
reg regDst,branch,memRead,memToReg,memWrite,ALUSrc,regWrite;
reg [2:0] ALUOp;
always @(instruction) begin
if (instruction==6'b0) begin
regDst <= 1'b1;
branch <= 1'b0;
memRead <= 1'b0;
memToReg <= 1'b0;
memWrite <= 1'b0;
ALUSrc <= 1'b0;
regWrite <= 1'b1;
ALUOp <= 3'b101;
end
else begin
case(instruction)
6'b001000 : //addi
begin
regDst <= 1'b0;
branch <= 1'b0;
memRead <= 1'b0;
memToReg <= 1'b0;
memWrite <= 1'b0;
ALUSrc <= 1'b1;
regWrite <= 1'b1;
ALUOp <= 3'b000;
end
6'b100011 : //lw
begin
regDst <= 1'b0;
branch <= 1'b0;
memRead <= 1'b1;
memToReg <= 1'b1;
memWrite <= 1'b0;
ALUSrc <= 1'b1;
regWrite <= 1'b1;
ALUOp <= 3'b000;
end
6'b101011 : //sw
begin
regDst <= 1'b0;
branch <= 1'b0;
memRead <= 1'b0;
memToReg <= 1'b0;
memWrite <= 1'b1;
ALUSrc <= 1'b1;
regWrite <= 1'b0;
ALUOp <= 3'b000;
end
6'b001100 : //andi
begin
regDst <= 1'b0;
branch <= 1'b0;
memRead <= 1'b0;
memToReg <= 1'b0;
memWrite <= 1'b0;
ALUSrc <= 1'b1;
regWrite <= 1'b1;
ALUOp <= 3'b001;
end
6'b001101 : //ori
begin
regDst <= 1'b0;
branch <= 1'b0;
memRead <= 1'b0;
memToReg <= 1'b0;
memWrite <= 1'b0;
ALUSrc <= 1'b1;
regWrite <= 1'b1;
ALUOp <= 3'b010;
end
6'b000100 : //beq
begin
regDst <= 1'b0;
branch <= 1'b1;
memRead <= 1'b0;
memToReg <= 1'b0;
memWrite <= 1'b0;
ALUSrc <= 1'b0;
regWrite <= 1'b0;
ALUOp <= 3'b011;
end
6'b000101 : //bne
begin
regDst <= 1'b0;
branch <= 1'b1;
memRead <= 1'b0;
memToReg <= 1'b0;
memWrite <= 1'b0;
ALUSrc <= 1'b0;
regWrite <= 1'b0;
ALUOp <= 3'b100;
end
endcase
end
end
endmodule