-
Notifications
You must be signed in to change notification settings - Fork 4
/
ctrl.v
110 lines (99 loc) · 1.95 KB
/
ctrl.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
module ctrl (ins, branch, jump, regDst, aluSrc, aluCtr, regWr, memWr, extOp, memtoReg);
input [31:0] ins;
output reg [3:0] aluCtr;
output reg branch;
output reg jump;
output reg regDst;
output reg aluSrc;
output reg regWr;
output reg memWr;
output reg extOp;
output reg memtoReg;
wire [5:0] op;
wire [5:0] func;
assign op = ins[31:26];
assign func = ins[5:0];
// Operation code;
parameter R = 6'b000000,
LW = 6'b100011,
SW = 6'b101011,
BEQ = 6'b000100,
J = 6'b000010,
ORI = 6'b001101;
// Function code;
parameter ADD = 6'b100000,
ADDU = 6'b100001,
SUB = 6'b100010,
SUBU = 6'b100011,
AND = 6'b100100,
OR = 6'b100101,
SLT = 6'b101010,
SLTU = 6'b101011;
always @ ( * ) begin
case (op)
R: begin// R-Type Instructions;
branch = 0;
jump = 0;
regDst = 1;
aluSrc = 0;
memtoReg = 0;
regWr = 1;
memWr = 0;
case (func)
ADD: aluCtr = 4'b0001;
ADDU: aluCtr = 4'b0000;
SUB: aluCtr = 4'b1001;
SUBU: aluCtr = 4'b1000;
AND: aluCtr = 4'b0010;
OR: aluCtr = 4'b0011;
SLT: aluCtr = 4'b1011;
SLTU: aluCtr = 4'b1010;
endcase
end
LW: begin// Load word;
branch = 0;
jump = 0;
regDst = 0;
aluSrc = 1;
memtoReg = 1;
regWr = 1;
memWr = 0;
extOp = 1;
aluCtr = 4'b0001;// add;
end
SW: begin// Store word;
branch = 0;
jump = 0;
aluSrc = 1;
regWr = 0;
memWr = 1;
extOp = 1;
aluCtr = 4'b0001;// add;
end
BEQ: begin// Branch on equal;
branch = 1;
jump = 0;
aluSrc = 0;
regWr = 0;
memWr = 0;
end
J: begin// J-Type Instructions;
branch = 0;
jump = 1;
regWr = 0;
memWr = 0;
end
ORI: begin// Or immediate;
branch = 0;
jump = 0;
regDst = 0;
aluSrc = 1;
memtoReg = 0;
regWr = 1;
memWr = 0;
extOp = 0;
aluCtr = 4'b0011;
end
endcase
end
endmodule // Control;