-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecoder.v
233 lines (213 loc) · 3.44 KB
/
decoder.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
module Instruction_Decoder(
input[4:0] opcode,
input interrupt,
output reg int_mux,
output reg[1:0] pc_mux,
output reg pc_save,
output reg[1:0] w_mux,
output reg mem_write,
output reg[3:0] alu_op
);
parameter W_ALU = 2'h0;
parameter W_MEM = 2'h1;
parameter W_LIT = 2'h2;
parameter W_WREG = 2'h3;
parameter PC_ADD = 2'h0;
parameter PC_WREG = 2'h1;
parameter PC_LIT = 2'h2;
parameter PC_SAVE = 2'h3;
parameter ALU_ROTL = 4'h0;
parameter ALU_ROTR = 4'h1;
parameter ALU_ADD = 4'h2;
parameter ALU_SUB = 4'h3;
parameter ALU_AND = 4'h4;
parameter ALU_OR = 4'h5;
parameter ALU_XOR = 4'h6;
parameter ALU_ZEROT = 4'h7;
parameter ALU_PCZERO = 4'h8;
parameter ALU_PCZEROBAR = 4'h9;
parameter ALU_NOP = 4'hA;
initial
begin
int_mux = 0;
pc_mux = 0;
pc_save = 0;
w_mux = 0;
mem_write = 0;
alu_op = 0;
end
always @(opcode, interrupt)
begin
int_mux = 1'b0; // "hardwired" off until iterrupt controller implemented in future milestone.
case (opcode[4:1])
// mm
4'h0 :
begin
if (opcode[0])
w_mux = W_WREG;
else
w_mux = W_MEM;
mem_write = opcode[0];
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_ZEROT;
end
// mwm
4'h1 :
begin
w_mux = W_WREG;
mem_write = 1'b1;
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_NOP;
end
//mlw
4'h2 :
begin
w_mux = W_LIT;
mem_write = 1'b0;
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_NOP;
end
// rlm
4'h3 :
begin
if (opcode[0])
w_mux = W_WREG;
else
w_mux = W_ALU;
mem_write = opcode[0];
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_ROTL;
end
//rrm
4'h4 :
begin
if (opcode[0])
w_mux = W_WREG;
else
w_mux = W_ALU;
mem_write = opcode[0];
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_ROTR;
end
//awm
4'h5 :
begin
if (opcode[0])
w_mux = W_WREG;
else
w_mux = W_ALU;
mem_write = opcode[0];
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_AND;
end
// owm
4'h6 :
begin
if (opcode[0])
w_mux = W_WREG;
else
w_mux = W_ALU;
mem_write = opcode[0];
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_OR;
end
// xwm
4'h7 :
begin
if (opcode[0])
w_mux = W_WREG;
else
w_mux = W_ALU;
mem_write = opcode[0];
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_XOR;
end
// add
4'h8 :
begin
if (opcode[0])
w_mux = W_WREG;
else
w_mux = W_ALU;
mem_write = opcode[0];
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_ADD;
end
// sub
4'h9 :
begin
if (opcode[0])
w_mux = W_WREG;
else
w_mux = W_ALU;
mem_write = opcode[0];
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_SUB;
end
// sms
4'hA :
begin
w_mux = W_WREG;
mem_write = 1'b0;
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_PCZERO;
end
// smc
4'hB :
begin
w_mux = W_WREG;
mem_write = 1'b0;
pc_mux = PC_ADD;
pc_save = 1'b0;
alu_op = ALU_PCZEROBAR;
end
// gol
4'hC :
begin
w_mux = W_WREG;
mem_write = 1'b0;
pc_mux = PC_LIT;
pc_save = 1'b0;
alu_op = ALU_NOP;
end
// gow
4'hD :
begin
w_mux = W_WREG;
mem_write = 1'b0;
pc_mux = PC_WREG;
pc_save = 1'b0;
alu_op = ALU_NOP;
end
// wfi
4'hE :
begin
w_mux = W_WREG;
mem_write = 1'b0;
pc_mux = PC_SAVE;
pc_save = 1'b1;
alu_op = ALU_NOP;
end
// rfi
4'hF :
begin
w_mux = W_WREG;
mem_write = 1'b0;
pc_mux = PC_SAVE;
pc_save = 1'b0;
alu_op = ALU_NOP;
end
endcase
end
endmodule