これは使用されているリップル キャリー加算器ですが、sub = 1 A = 4 B = 3 の場合、プログラムはオーバーフローを返さず、合計は 0110 ではなく 1100 になります。
module fullAdder(A, B, Cin, sum, Cout);
input A, B, Cin;
output sum, Cout;
assign sum = A^B^Cin;
assign Cout = (Cin&A) | (Cin&B) |(A&B);
endmodule
module RCA4bit(A, B, C0, sum, C1, overflow);
input [3:0] A;
input [3:0] B;
output [3:0] sum;
input C0;
output C1;
output overflow;
wire [2:0] carry;
fullAdder RCA1(A[0], B[0], C0, sum[0], carry[0]);
fullAdder RCA2(A[1], B[1], carry[0], sum[1], carry[1]);
fullAdder RCA3(A[2], B[2], carry[1], sum[2], carry[2]);
fullAdder RCA4(A[3], B[3], carry[2], sum[3], C1);
assign overflow = C1 ^ carry[2];
endmodule
module RCA4bit2cmp(A, B, sub, sum, C1, overflow);
input [3:0] A;
input [3:0] B;
output [3:0] sum;
input sub;
output C1;
output overflow;
wire [3:0]invB;
assign invB = sub?~B:B;
RCL4bit RC4(A, invB, sub, sum, C1, overflow);
endmodule