Electrical – problem with 6 bit adder

addercircuit-designvivado

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?

Best Answer

The way I did the calculations using pen and paper were wrong.

For sel = 1,

When x = 111111 and y = 100000

y'= 011111

I was adding y' and 1 first and then adding x. This way is wrong.

Binary numbers are added bit by bit. So the sel bit which is 1 has to be added with the Least significant bits first and so on. Add x, y' and sel together.

  111111
  011111
      +1
  ______
1 011111 ,  Value of Overflow = 1 ex-or 1 = 0 ( Correct ) 


If I add y' and 1 together first then 
  011111
       1
  ______
  100000

  111111
  100000
  ______
1 011111   , Value of Overflow = 1 ex-or 0 = 1 ( Incorrect ) 

Similarly for the other case.