-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALUControl.v
166 lines (162 loc) · 4.81 KB
/
ALUControl.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2023/01/20 14:46:26
// Design Name:
// Module Name: ALUControl
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module ALUControl(
input [3:0] funct,
input [3:0] ALUOp,
output reg [3:0] ALUcntl
);
/* ALU control parameters */
parameter AND = 4'b0000;
parameter OR = 4'b0001;
parameter XOR = 4'b0010;
parameter LSL = 4'b0011;
parameter RSL = 4'b0100;
parameter RSA = 4'b0101;
parameter ADD = 4'b0110;
parameter SUB = 4'b0111;
always @ (funct or ALUOp) begin
case (ALUOp)
//LB, LH, LW, LBU, LHU
4'b0000: begin
ALUcntl <= ADD;
end
//ADDI, SLTI, SLTIU, XORI, ORI, ANDI, SLLI, SRLI, SRAI
4'b0001: begin
case (funct[2:0])
//ADDI
3'b000: begin
ALUcntl <= ADD;
end
3'b001: begin
//SLLI
if (funct[3] == 0) begin
ALUcntl <= LSL;
end
else begin
ALUcntl <= 4'bxxxx;
end
end
//SLTI
3'b010: begin
ALUcntl <= SUB;
end
//SLTIU
3'b011: begin
ALUcntl <= SUB;
end
//XORI
3'b100: begin
ALUcntl <= XOR;
end
3'b101: begin
//SRLI
if (funct[3] == 0) begin
ALUcntl <= RSL;
end
//SRAI
else begin
ALUcntl <= RSA;
end
end
//ORI
3'b110: begin
ALUcntl <= OR;
end
//ANDI
3'b111: begin
ALUcntl <= AND;
end
default: begin
ALUcntl <= 4'bxxxx;
end
endcase
end
//AUIPC
4'b0010: begin
ALUcntl <= ADD;
end
//SB, SH, SW
4'b0011: begin
if (funct[2:0] == 3'b000 || funct[2:0] == 3'b001 || funct[2:0] == 3'b010) begin
ALUcntl <= ADD;
end
else begin
ALUcntl <= 4'bxxxx;
end
end
//ADD, SUB, SLL, SLT, SLTU, XOR, SRL, SRA, OR, AND
4'b0100: begin
case (funct[2:0])
3'b000: begin
//ADD
if (funct[3] == 0) begin
ALUcntl <= ADD;
end
//SUB
else begin
ALUcntl <= SUB;
end
end
//SLL
3'b001: begin
ALUcntl <= LSL;
end
//SLT
3'b010: begin
ALUcntl <= SUB;
end
//SLTU
3'b011: begin
ALUcntl <= SUB;
end
//XOR
3'b100: begin
ALUcntl <= XOR;
end
3'b101: begin
//SRL
if (funct[3] == 0) begin
ALUcntl <= RSL;
end
//SRA
else begin
ALUcntl <= RSA;
end
end
//OR
3'b110: begin
ALUcntl <= OR;
end
//AND
3'b111: begin
ALUcntl <= AND;
end
default: begin
ALUcntl <= 4'bxxxx;
end
endcase
end
default: begin
ALUcntl <= 4'bxxxx;
end
endcase
end
endmodule