Adder–subtractor
   HOME

TheInfoList



OR:

In
digital circuit In theoretical computer science, a circuit is a model of computation in which input values proceed through a sequence of gates, each of which computes a function. Circuits of this kind provide a generalization of Boolean circuits and a mathematica ...
s, an adder–subtractor is a circuit that is capable of adding or subtracting numbers (in particular,
binary Binary may refer to: Science and technology Mathematics * Binary number, a representation of numbers using only two digits (0 and 1) * Binary function, a function that takes two arguments * Binary operation, a mathematical operation that ta ...
). 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 Two's complement is a mathematical operation to reversibly convert a positive binary number into a negative binary number with equivalent (but negative) value, using the binary digit with the greatest place value (the leftmost bit in big- endian ...
. 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 In electronics, a multiplexer (or mux; spelled sometimes as multiplexor), also known as a data selector, is a device that selects between several analog or digital input signals and forwards the selected input to a single output line. The sel ...
where: * Input 0 (''I''0) is ''A'' * Input 1 (''I''1) is that has control input ''D'' that is also connected to the initial carry, then the modified adder performs * addition when , or * subtraction when . This works because when the ''A'' input to the adder is really and the carry in is 1. Adding ''B'' to and 1 yields the desired subtraction of . A way you can mark number ''A'' as positive or negative without using a multiplexer on each bit is to use an
XOR gate XOR gate (sometimes EOR, or EXOR and pronounced as Exclusive OR) is a digital logic gate that gives a true (1 or HIGH) output when the number of true inputs is odd. An XOR gate implements an exclusive or (\nleftrightarrow) from mathematical log ...
to precede each bit instead. * The first input to the XOR gate is the actual input bit * The second input to the XOR gate for each is the control input ''D'' This produces the same
truth table A truth table is a mathematical table used in logic—specifically in connection with Boolean algebra (logic), Boolean algebra, boolean functions, and propositional calculus—which sets out the functional values of logical expression (mathematics) ...
for the bit arriving at the adder as the multiplexer solution does since the XOR gate output will be what the input bit is when and the inverted input bit when .


Role in the arithmetic logic unit

Adders are a part of the core of an
arithmetic logic unit In computing, an arithmetic logic unit (ALU) is a combinational digital circuit that performs arithmetic and bitwise operations on integer binary numbers. This is in contrast to a floating-point unit (FPU), which operates on floating point numb ...
(ALU). The
control unit The control unit (CU) is a component of a computer's central processing unit (CPU) that directs the operation of the processor. A CU typically uses a binary decoder to convert coded instructions into timing and control signals that direct the op ...
decides which operations an ALU should perform (based on the
op code In computing, an opcode (abbreviated from operation code, also known as instruction machine code, instruction code, instruction syllable, instruction parcel or opstring) is the portion of a machine language instruction that specifies the operat ...
being executed) 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 (in conjunction with ) to yield the
two's complement Two's complement is a mathematical operation to reversibly convert a positive binary number into a negative binary number with equivalent (but negative) value, using the binary digit with the greatest place value (the leftmost bit in big- endian ...
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 (with both the ''Ai'' and ''Bi'' inputs set to zero and ) * 1 (with both the ''Ai'' and ''Bi'' inputs set to zero and ) * ''A'' (with the ''Bi'' input set to zero) * ''B'' (with the ''Ai'' input set to zero) * (with the ''Bi'' input set to zero and ) * (with the ''Ai'' input set to zero and ) * * * * (with ''Ai'' set to invert; ''Bi'' set to zero; and ) * −''A'' (with ''Ai'' set to invert; ''Bi'' set to zero; and ) * (with ''Bi'' set to invert; ''Ai'' set to zero; and ) * −''B'' (with ''Bi'' set to invert; ''Ai'' set to zero; and ) By adding more logic in front of the adder, a single adder can be converted into much more than just an adder—an ALU.


See also

*
Adder (electronics) An adder, or summer, is a digital circuit that performs addition of numbers. In many computers and other kinds of processors adders are used in the arithmetic logic units (ALUs). They are also used in other parts of the processor, where they are ...
*
Carry-lookahead adder A carry-lookahead adder (CLA) or fast adder is a type of electronics adder used in digital logic. A carry-lookahead adder improves speed by reducing the amount of time required to determine carry bits. It can be contrasted with the simpler, b ...
* Carry-save adder *
Adding machine An adding machine is a class of mechanical calculator, usually specialized for bookkeeping calculations. In the United States, the earliest adding machines were usually built to read in dollars and cents. Adding machines were ubiquitous of ...
* Subtractor


References

{{DEFAULTSORT:Adder-subtractor Telecommunications equipment Binary arithmetic Adders (electronics) Arithmetic logic circuits