currently having problem with my carry in to carry out.
i have used this for my LSB
assign S=A^(~B+1)^Cin;
assign COUT=(A&~B)|((CIN+1)&(A^~B));
and this for my 3 higher bits.
assign S=A^~B^Cin;
assign Cout=(A&~B)|(Cin&(A^~B));
adder
Best Answer
RYour expressions for individual bits shouldn't use the term "B+1", that can have three possible values (0,1,2) and require two bits to express.
Your expressions for all 4 bits of the adder should be the same:
Sn = An^~Bn^Cin; Coutn = (An&~Bn)|(Cin&(An^~Bn));
Where 'n' represents the bit number.
The Cin for the entire adder should be set to a 1 to do the complement + 1 function.
Try this approach to thinking about it:
Forget about A for the moment. How would you create the 2's complement of B with your logic?
You would put the complement of B into the 4 input lines of the adder, then to add the 1 you would set the carry in. This should result in the 2's complement of B at the output.
Now add A into the other 4 input pins. You should get the A-B at the output. The carry output is then used as an overflow status bit that tells you about the relative magnitude of the two operands.