I am trying to build a 32-bit ALU in Verilog. I've implemented a 1-bit ALU at the beginning. The ALU should have only 4 functions, not all of them: add, sub, and, or. This is my code:
module ALU(
input wire [3:0] OPCode,
input wire Operand1,
input wire Operand2,
input wire cin,
output reg Result,
output reg Cout
);
always@(*)
begin
case(OPCode)
4'b0000: Result = Operand1&Operand2;
4'b0001: Result = Operand1|Operand2;
4'b0010:
begin
Result = cin ^(Operand1 ^ (Operand2 ^ cin));
Cout = ((Operand2 ^ cin) & Operand1) | ((Operand1 ^ (Operand2 ^ cin)) & cin);
end
4'b0110:
begin
Result = cin ^(Operand1 ^ (Operand2 ^ cin));
Cout = ((Operand2 ^ cin) & Operand1) | ((Operand1 ^ (Operand2 ^ cin)) & cin);
end
endcase
end
endmodule
The problem here is that it generates unnecessary LATCH gates. I already know it's because I'm not covering all cases in my case statement; however, these are the only cases that I have.
What should I do to fix my case statement?