I am working on Subtractor circuits using Adder circuits. I have to do x-y.
Suppose x = 111111 , y = 100000 Using the 6 bit adder circuit I created the overflow flag is coming to be 0 but when I solve it using pen and paper the overflow is coming to be 1.
When x = 000000 and y = 000000 the Carry out flag is coming to be 1 but using pen and paper it is coming to be 0.
I have used the basic logic used to create Adder circuits and for evaluation of flags.
I created 15 test cases. Only these two test cases did not agree with these flags. The final answer they displayed was correct.
Calculation that I did on pen and paper:
x = 111111, y = 100000
y'+1 = 100000
x + y' + 1 = 011111 with Carry out = 1 and overflow = ex-or of 1 and 0 = 1
x = 000000, y = 000000
y'+1 = 000000
x + y' + 1 = 000000 with carry out = 0 and overflow = ex-or of 0 and 0 = 0
What mistake I might be doing?
I think it has to do something with 2s complements because 2s complement of 0000000 and 100000 are the numbers themselves.
I have created the circuit in vivado.
My code is this: Full 1bit Adder:
module FullAdder( a,b,cin,s,cout ) ;
input wire a,b,cin ;
output wire s,cout ;
assign s = cin^a^b;
assign cout = (b&cin) | (a&cin) | (a&b) ;
endmodule
Code for 6 bit adder:
`timescale 1ns/ 1ps
module sixbit_ripple_adder
(
input wire[5:0] x,y,
input wire sel,
output wire overflow, c_out,
output wire[5:0] sum
) ;
wire c1,c2,c3,c4,c5,c6 ;
FullAdder f1 ( .a(x[0]) , .b(y[0]^sel) , .cin(sel) , .s(sum[0]) , .cout(c1) ) ;
FullAdder f2 ( .a(x[1]) , .b(y[1]^sel) , .cin(c1) , .s(sum[1]) , .cout(c2) ) ;
FullAdder f3 ( .a(x[2]) , .b(y[2]^sel) , .cin(c2) , .s(sum[2]) , .cout(c3) ) ;
FullAdder f4 ( .a(x[3]) , .b(y[3]^sel) , .cin(c3) , .s(sum[3]) , .cout(c4) ) ;
FullAdder f5 ( .a(x[4]) , .b(y[4]^sel) , .cin(c4) , .s(sum[4]) , .cout(c5) ) ;
FullAdder f6 ( .a(x[5]) , .b(y[5]^sel) , .cin(c5) , .s(sum[5]) , .cout(c6) ) ;
assign c_out = c6 ;
assign overflow = c5^c6 ;
endmodule
Value of sel for both the test cases is 1.
What am I missing?