Fixed bug in adder/subtracter where code assuming width was the bit width was not updated when moving to the 2**N approach required by the assignment. Updated adder/subtracter testbench to correctly instantiate the asser/subtracter and removed unused variable

This commit is contained in:
riley committed 2026-09-08 22:49:22 +10:00
1 parent 42f4e661dc
commit 5acf1c8b87
2 files changed
+5 -7

No files matched your search

+4 -4
View File
@@ -7,11 +7,11 @@ module asu #(parameter width = 2)(
always_comb begin always_comb begin
// A + (sub) ? B : -B // A + (sub) ? B : -B
// Adds an extra bit to all operands to calculate the carry bit. Not optimal for hardware synthesis // Adds an extra bit to all operands to calculate the carry bit. Not optimal for hardware synthesis
operand = (B ^ {(width){op}}); operand = (B ^ {(2**width){op}});
{COUT, OUT_1} = A + operand + {{(width-1){1'b0}}, op}; {COUT, OUT_1} = A + operand + {{(2**width-1){1'b0}}, op};
end end
// Need to do this outside of the always_comb block because parameter-based bitslicing/indexing isn't supported? // Need to do this outside of the always_comb block because parameter-based bitslicing/indexing isn't supported?
// Cin for width-2'th bit to later be xor'ed with COUT to determine if a signed overflow occured for the MIPS architecture // Cin for final bit in adder to later be xor'ed with COUT to determine if a signed overflow occured for the MIPS architecture
assign OUT_CIN = A[width-1] ^ operand[width-1] ^ OUT_1[width-1]; assign OUT_CIN = A[2**width-1] ^ operand[2**width-1] ^ OUT_1[2**width-1];
endmodule endmodule
+1 -3
View File
@@ -11,9 +11,7 @@ module asu_tb #(width=8)();
logic [0:0] Cout_exp; logic [0:0] Cout_exp;
logic [0:0] Cin_exp; // TODO logic [0:0] Cin_exp; // TODO
logic [0:0] Signed_overflow; asu #($clog2(width)) dut(op, A, B, C, Cout, Cin);
asu #(width) dut(op, A, B, C, Cout, Cin);
integer error_count; integer error_count;
initial begin initial begin