-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecoder.v
101 lines (74 loc) · 1.6 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
// Author:0711282 邱頎霖
module Decoder(
instr_op_i,
RegWrite_o,
ALU_op_o,
ALUSrc_o,
RegDst_o,
Branch_o
);
//I/O ports
input [6-1:0] instr_op_i;
output RegWrite_o;
output [3-1:0] ALU_op_o;
output ALUSrc_o;
output RegDst_o;
output Branch_o;
//Internal Signals
reg [3-1:0] ALU_op_o;
reg ALUSrc_o;
reg RegWrite_o;
reg RegDst_o;
reg Branch_o;
always @( * ) begin
if(instr_op_i==0)begin
RegWrite_o <= 1;
ALU_op_o <= 3'b000;
ALUSrc_o <= 0;
RegDst_o <= 1;
Branch_o <= 0;
end
else if(instr_op_i== 8)begin //addi
RegWrite_o <= 1;
ALU_op_o <= 3'b001;
ALUSrc_o <= 1;
RegDst_o <= 0;
Branch_o <= 0;
end
else if(instr_op_i== 11)begin //sltiu
RegWrite_o <= 1;
ALU_op_o <= 3'b010;
ALUSrc_o <= 1;
RegDst_o <= 0;
Branch_o <= 0;
end
else if(instr_op_i== 4)begin //beq
RegWrite_o <= 0;
ALU_op_o <= 3'b100;
ALUSrc_o <= 0;
RegDst_o <= 0;
Branch_o <= 1; // not important
end
else if(instr_op_i== 15)begin //lui
RegWrite_o <= 1;
ALU_op_o <= 3'b011;
ALUSrc_o <= 1;
RegDst_o <= 0;
Branch_o <= 0;
end
else if(instr_op_i== 13)begin // ori
RegWrite_o <= 1;
ALU_op_o <= 3'b111;
ALUSrc_o <= 1;
RegDst_o <= 0;
Branch_o <= 0;
end
else if(instr_op_i==5)begin //bne
RegWrite_o <= 0;
ALU_op_o <= 3'b110;
ALUSrc_o <= 0;
RegDst_o <= 0;
Branch_o <= 1; // not important
end
end
endmodule