Adder–subtractor
In digital circuits, an adder–subtractor is a circuit that is capable of adding or subtracting numbers. Below is a circuit that adds or subtracts depending on a control signal. It is also possible to construct a circuit that performs both addition and subtraction at the same time.
Construction
Having an n-bit adder for A and B, then. Then, assume the numbers are in two's complement. Then to perform, two's complement theory says to invert each bit of A with a NOT gate then add one. This yields, which is easy to do with a slightly modified adder.By preceding each A input bit on the adder with a 2-to-1 multiplexer where:
- Input 0 is A
- Input 1 is
- addition when, or
- subtraction when.
A way you can mark number A as positive or negative without using a multiplexer on each bit is to use an XOR gate to precede each bit instead.
- The first input to the XOR gate is the actual input bit
- The second input for each XOR gate is the control input D
Role in the arithmetic logic unit
Adders are a part of the core of an arithmetic logic unit. The control unit decides which operations an ALU should perform and sets the ALU operation. The D input to the adder–subtractor above would be one such control line from the control unit.The adder–subtractor above could easily be extended to include more functions. For example, a 2-to-1 multiplexer could be introduced on each Bi that would switch between zero and Bi; this could be used to yield the two's complement of A since.
A further step would be to change the 2-to-1 multiplex on A to a 4-to-1 with the third input being zero, then replicating this on Bi thus yielding the following output functions:
- 0
- 1 A B
- −A
- −B