2023-10-23 05:15:21 +00:00
|
|
|
module alu (input [31:0] in_a, in_b,
|
|
|
|
input [3:0] op_code,
|
2023-10-20 09:48:18 +00:00
|
|
|
output reg [31:0] out);
|
|
|
|
|
2023-10-24 01:49:29 +00:00
|
|
|
`include "alu_func.vh"
|
2023-10-24 10:36:34 +00:00
|
|
|
|
|
|
|
reg signed [31:0] s_in_a;
|
|
|
|
reg signed [31:0] s_in_b;
|
2023-10-24 01:49:29 +00:00
|
|
|
|
2023-10-20 09:48:18 +00:00
|
|
|
always@ (*) begin
|
2023-10-24 10:36:34 +00:00
|
|
|
s_in_a = in_a;
|
|
|
|
s_in_b = in_b;
|
2023-10-20 09:48:18 +00:00
|
|
|
case (op_code)
|
2023-10-24 01:49:29 +00:00
|
|
|
ADD : out <= in_a + in_b;
|
|
|
|
SUB : out <= in_a - in_b;
|
|
|
|
SLL : out <= in_a << in_b;
|
2023-10-24 10:36:34 +00:00
|
|
|
SLT : out <= (s_in_a < s_in_b) ? 1 : 0;
|
2023-10-24 01:49:29 +00:00
|
|
|
SLTU : out <= (in_a < in_b) ? 1 : 0;
|
|
|
|
XOR : out <= in_a ^ in_b;
|
|
|
|
SRL : out <= in_a >> in_b;
|
2023-10-24 10:36:34 +00:00
|
|
|
SRA : out <= s_in_a >>> in_b;
|
2023-10-24 01:49:29 +00:00
|
|
|
OR : out <= in_a | in_b;
|
|
|
|
AND : out <= in_a & in_b;
|
2023-10-20 09:48:18 +00:00
|
|
|
default : out <= 32'b0;
|
|
|
|
endcase
|
|
|
|
end
|
2023-10-11 08:43:36 +00:00
|
|
|
|
2023-10-20 09:48:18 +00:00
|
|
|
endmodule
|