Control.v.bak
3.39 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
module Control(opcode, funct, regdst, regwrite, alusrc, aluctrl, memread, memwrite, memtoreg, branch, jump, jumpreg);
input[5:0] opcode;
input[5:0] funct;
output reg regdst, regwrite, alusrc, memread, memwrite, memtoreg, branch, jump, jumpreg;
output reg[3:0] aluctrl;
always @(*) begin
case(opcode)
6'b000000: begin // R type instruction
regdst = 1'b1;
regwrite = 1'b1;
alusrc = 1'b0;
memread = 1'b0;
memwrite = 1'b0;
memtoreg = 1'b0;
branch = 1'b0;
jump = 1'b0;
jumpreg = 1'b0;
case(funct)
6'b100000: aluctrl = 4'b0010; // add
6'b100001: aluctrl = 4'b0010; // addu
6'b100010: aluctrl = 4'b0110; // sub
6'b100011: aluctrl = 4'b0110; // subu
6'b100100: aluctrl = 4'b0000; // and
6'b100101: aluctrl = 4'b0001; // or
6'b100110: aluctrl = 4'b1101; // xor
6'b011000: aluctrl = 4'b1000; // mult
6'b011001: aluctrl = 4'b1000; // multu
6'b011010: aluctrl = 4'b1001; // div
6'b011011: aluctrl = 4'b1001; // divu
6'b101010: aluctrl = 4'b0111; // slt
6'b101011: aluctrl = 4'b0111; // sltu
6'b010000: aluctrl = 4'b1010; // mfhi
6'b010010: aluctrl = 4'b1011; // mflo
6'b001000: begin // jr
// regdst = 1'bx;
regwrite = 1'b0;
// alusrc = 1'bx;
aluctrl = 4'b1111;
memread = 1'b0;
memwrite = 1'b0;
// memtoreg = 1'bx;
branch = 1'b0;
jump = 1'b0;
jumpreg = 1'b1;
end
default: aluctrl = 4'b1111;
endcase
end
6'b001000: begin // addi instruction
regdst = 1'b0;
regwrite = 1'b1;
alusrc = 1'b1;
aluctrl = 4'b0010; // add
memread = 1'b0;
memwrite = 1'b0;
memtoreg = 1'b0;
branch = 1'b0;
jump = 1'b0;
jumpreg = 1'b0;
end
6'b001001: begin // addiu instruction
regdst = 1'b0;
regwrite = 1'b1;
alusrc = 1'b1;
aluctrl = 4'b0010; // add
memread = 1'b0;
memwrite = 1'b0;
memtoreg = 1'b0;
branch = 1'b0;
jump = 1'b0;
jumpreg = 1'b0;
end
6'b001100: begin // andi instruction
regdst = 1'b0;
regwrite = 1'b1;
alusrc = 1'b1;
aluctrl = 4'b0000; // and
memread = 1'b0;
memwrite = 1'b0;
memtoreg = 1'b0;
branch = 1'b0;
jump = 1'b0;
jumpreg = 1'b0;
end
6'b000100: begin // beq instruction
// regdst = 1'bx; // don't care
regwrite = 1'b0;
alusrc = 1'b0;
aluctrl = 4'b0110; // sub
memread = 1'b0;
memwrite = 1'b0;
// memtoreg = 1'bx;
branch = 1'b1;
jump = 1'b0;
jumpreg = 1'b0;
end
6'b000010: begin // jump instruction
// regdst = 1'bx;
regwrite = 1'b0;
// alusrc = 1'bx;
aluctrl = 4'b1111;
memread = 1'b0;
memwrite = 1'b0;
// memtoreg = 1'bx;
branch = 1'b0;
jump = 1'b1;
jumpreg = 1'b0;
end
6'b100011: begin // lw instruction
regdst = 1'b0;
regwrite = 1'b1;
alusrc = 1'b1;
aluctrl = 4'b0010; // add
memread = 1'b1;
memwrite = 1'b0;
memtoreg = 1'b1;
branch = 1'b0;
jump = 1'b0;
jumpreg = 1'b0;
end
6'b101011: begin // sw instruction
regdst = 1'b0;
regwrite = 1'b0;
alusrc = 1'b1;
aluctrl = 4'b0010; // add
memread = 1'b0;
memwrite = 1'b1;
// memtoreg = 1'bx;
branch = 1'b0;
jump = 1'b0;
jumpreg = 1'b0;
end
default: begin // unknown instruction
// regdst = 1'bx;
regwrite = 1'b0;
// alusrc = 1'bx;
aluctrl = 4'b1111;
memread = 1'b0;
memwrite = 1'b0;
// memtoreg = 1'bx;
branch = 1'b0;
jump = 1'b0;
jumpreg = 1'b0;
end
endcase
end
endmodule