-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalu.v
34 lines (30 loc) · 930 Bytes
/
alu.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
module alu
(
/* inputs */
input signed [31:0] i_op_a,
input signed [31:0] i_op_b,
input [ 3:0] i_op,
/* outputs */
output reg [31:0] o_res,
output o_zf
);
assign o_zf = (o_res == 32'd0);
always_comb
begin
case (i_op)
4'b0000: o_res = i_op_a + i_op_b;
4'b0001: o_res = i_op_a - i_op_b;
4'b0010: o_res = i_op_a << i_op_b[4:0];
4'b0011: o_res = (i_op_a < i_op_b) ? 32'b1 : 32'b0;
4'b0100:
o_res = ($unsigned(i_op_a) < $unsigned(i_op_b))
? 32'b1 : 32'b0;
4'b0101: o_res = i_op_a ^ i_op_b;
4'b0110: o_res = i_op_a >> i_op_b[4:0];
4'b0111: o_res = i_op_a >>> i_op_b[4:0];
4'b1000: o_res = i_op_a | i_op_b;
4'b1001: o_res = i_op_a & i_op_b;
default: o_res = 32'd0;
endcase
end
endmodule