I'm testing a basic ALU in Vivado using a testbench.
One of my tests checks that overflow works correctly. The test has the following form:
0000 0001 + ffff ffff = 0000 0001
But, I'm getting 0000 0000
instead. My arithmetic
module is defined as follows:
module arithmetic(
input [3:0] aluOp,
input [31:0] a,
input [31:0] b,
output reg [31:0] result
);
reg [31:0] temp;
always @(*) begin
case (aluOp)
4'b0000: result = a + b;
4'b0010: result = a - b;
4'b1010: begin
temp = a-b;
result = {temp[31], 31'b0};
end
endcase
end
endmodule
It works for the other test cases but not for this one. Does anyone know why Verilog isn't overflowing as expected?
0000 0001 + ffff ffff
to overflow to0000 0001
and not0000 0000
?0000 0001
doesn't make sense. \$\endgroup\$