adder/subtractor

Thread Starter

Edman83

Joined Jan 21, 2025
34
1742387350889.png
The problems goes in part "b." in the constructing of a "subtractor". So I just thought to make all C inputs - inverted B to represent negative B as 1's complement binary data type and add it with A inputs how it is accomplished with 2's complement data type. (Falstad.com)
1742387846878.png

But turned out that author of the book was right :
1742387981820.png
It's not so easy task as i have assumed :). First of all, i didn't start to try implement 2's complement because i have no idea how to realize second complement, namely adding the 1 to the reversed bits of positive number. You can't just realize it with invertor. So here is the problem, now i know that this is the simplest way to do it, represent C inputs like 2's complement negative B inputs. But I have no ideas so far. Could you kind people give me some advice?
The book: "Introduction to Computing Systems" by Yale N. Patt and Sanjay J. Patel. 3rd edition.
 

Papabravo

Joined Feb 24, 2006
22,058
Yes you can. The multiplexer allows you to select the number or the 1's complement. The carry into the least significant adder will add the 1 to the 1's complement of B and the result will be either:

  1. A + B + 0, a Ci of 0
  2. A + B* + 1, a Ci of 1
Example:

  1. X = 0, A = 0b0110, B = 0b0101, Ci = 0 ; Sum = 0b1011 = 0d11 as you would expect
  2. X = 1, A = 0b0110, B* = 0b1010, Ci = 1; Sum = 0b0001 = 0d01, with a Carry out =1 as you would expect
prefixing a string of binary digits with a "0b" is often done for clarity in programming languages
prefixing a string of decimal digits with "0d" is often done for clarity in programming languages
Ci is an abbreviation for "Carry in"
Co is an abbreviation for "Carry out'
B* is a common way of indication the "1's complement of B"
 

Thread Starter

Edman83

Joined Jan 21, 2025
34
Yes you can. The multiplexer allows you to select the number or the 1's complement. The carry into the least significant adder will add the 1 to the 1's complement of B and the result will be either:

  1. A + B + 0, a Ci of 0
  2. A + B* + 1, a Ci of 1
Example:

  1. X = 0, A = 0b0110, B = 0b0101, Ci = 0 ; Sum = 0b1011 = 0d11 as you would expect
  2. X = 1, A = 0b0110, B* = 0b1010, Ci = 1; Sum = 0b0001 = 0d01, with a Carry out =1 as you would expect
prefixing a string of binary digits with a "0b" is often done for clarity in programming languages
prefixing a string of decimal digits with "0d" is often done for clarity in programming languages
Ci is an abbreviation for "Carry in"
Co is an abbreviation for "Carry out'
B* is a common way of indication the "1's complement of B"
If you meant this:
1742425549445.png

or this:
1742425605031.png

It doesn't work for both cases. It either works only for some values or violate logic of positive B summing.
In my scheme if X=L it should sum positive B, X=H it should sum negative B.
For example A = 0b0110 = 0d06, B = 0b0101 = 0d05
A + B = 0b1011 = 0d1, A - B = 0b0001 = 0d0001
1742426651122.png1742426680532.png

In case of A-B it works as expected, but in case of A+B it adds excessive 1 to the answer due to invertor in Cin of the first adder.

1742426935042.png1742426956576.png

Here A+B works as expected, but in case A-B we get wrong answer. It should added here 1 to Cin but It didn't. So we get 0b10000 as a result with overflow as expected but without expected +1.
 

WBahn

Joined Mar 31, 2012
32,704
You have a Carry In to the least-significant bit's Full Adder, right?

When you want to ADD A and B, you don't want to carry anything in to that LSB, right?

When you want to SUBTRACT B from A, you DO want to carry something in to the LSB, right?

Can you think of a signal that you have available to you that is a 0 when you want to ADD and a 1 when you want to SUBTRACT?
 

Thread Starter

Edman83

Joined Jan 21, 2025
34
You have a Carry In to the least-significant bit's Full Adder, right?

When you want to ADD A and B, you don't want to carry anything in to that LSB, right?

When you want to SUBTRACT B from A, you DO want to carry something in to the LSB, right?

Can you think of a signal that you have available to you that is a 0 when you want to ADD and a 1 when you want to SUBTRACT?
Damn, how could I not figure this out on my own? I feel so stupid. Thank you so much!! Here the result: Falstad.com
 

micoffey

Joined Aug 10, 2025
17
The value on wire x lets you do whatever it is programmed to do, which can be whatever you want. You can negate the answer, void the answer, force 1, or force 0. It's really up to you. Just be sure to hold to whatever assumptions you make with the future steps, to ensure that your solution is logically coherent.
 

WBahn

Joined Mar 31, 2012
32,704
The value on wire x lets you do whatever it is programmed to do, which can be whatever you want. You can negate the answer, void the answer, force 1, or force 0. It's really up to you. Just be sure to hold to whatever assumptions you make with the future steps, to ensure that your solution is logically coherent.
Note that the TS had their issue resolved over four months ago. Leaving that aside, your response makes no sense in the context of the problem that the TS was tasked with, which is to implement an adder/subtractor (in part b of the problem) with the circuit presented in part a as a huge hint.
 
Top