-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAluV2.sv.bak
27 lines (23 loc) · 906 Bytes
/
AluV2.sv.bak
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
module aluV2(input logic [31:0] a, b,
input logic [2:0] ALUControl,
output logic [31:0] Result,
output logic [3:0] ALUFlags);
logic neg, zero, carry, overflow;
logic [31:0] condinvb;
logic [32:0] sum;
assign condinvb = ALUControl[0] ? ~b : b;
assign sum = a + condinvb + ALUControl[0];
always_comb
casex (ALUControl[2:0])
3'b00?: Result = sum;
3'b010: Result = a & b;
3'b011: Result = a | b;
3'b100: Result = a ^ b;
default: Result = 32'bx; // undefined
endcase
assign neg = Result[31];
assign zero = (Result == 32'b0) | (ALUControl[1] == 1'b1 & Result == 32'b1);
assign carry = (ALUControl[1] == 1'b0) & sum[32];
assign overflow = (ALUControl[1] == 1'b0) & ~(a[31] ^ b[31] ^ ALUControl[0]) & (a[31] ^ sum[31]);
assign ALUFlags = {neg, zero, carry, overflow};
endmodule