Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Adder–subtractor
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Computing circuit}} {{Sidebar arithmetic logic circuits|expand=Components|expand-components=AdderSubtractor}} {{more citations needed|date=June 2022|bot=yes}} In [[digital circuit]]s, an '''adder–subtractor''' is a circuit that is capable of [[adder (electronics)|adding]] or [[subtractor|subtracting]] numbers (in particular, [[binary numeral system|binary]]). 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.<ref>{{cite news |last=Teja |first=Ravi |url=https://www.electronicshub.org/binary-adder-and-subtractor/ |title=Binary Adder and Subtractor |work=Electronics Hub |date=2021-04-21 |accessdate=2022-06-01 }}</ref> ==Construction== [[Image:4-bit ripple carry adder-subtracter.svg|thumb|400px|A 4-bit ripple-carry adder–subtractor based on a 4-bit adder that performs [[two's complement]] on ''A'' when {{nowrap|1=''D'' = 1}} to yield {{nowrap|1=''S'' = ''B'' − ''A''}}.]] Having an ''n''-bit adder for ''A'' and ''B'', then {{nowrap|1=''S'' = ''A'' + ''B''}}. Then, assume the numbers are in [[two's complement]]. Then to perform {{nowrap|''B'' − ''A''}}, two's complement theory says to invert each bit of ''A'' with a [[NOT gate]] then add one. This yields {{nowrap|1=''S'' = ''B'' + {{overline|''A''}} + 1}}, 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 (''I''<sub>0</sub>) is ''A'' * Input 1 (''I''<sub>1</sub>) is {{overline|''A''}} that has control input ''D'' that is also connected to the initial carry, then the modified adder performs * addition when {{nowrap|1=''D'' = 0}}, or * subtraction when {{nowrap|1=''D'' = 1}}. This works because when {{nowrap|1=''D'' = 1}} the ''A'' input to the adder is really {{overline|''A''}} and the carry in is 1. Adding ''B'' to {{overline|''A''}} and 1 yields the desired subtraction of {{nowrap|''B'' − ''A''}}. 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'' This produces the same [[truth table]] 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 {{nowrap|1=''D'' = 0}} and the inverted input bit when {{nowrap|1=''D'' = 1}}. ==Role in the arithmetic logic unit== {{main|Arithmetic logic unit}} Adders are a part of the core of an [[arithmetic logic unit]] (ALU). The [[control unit]] decides which operations an ALU should perform (based on the [[op code]] 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 ''B<sub>i</sub>'' that would switch between zero and ''B<sub>i</sub>''; this could be used (in conjunction with {{nowrap|1=''D'' = 1}}) to yield the [[two's complement]] of ''A'' since {{nowrap|1=−''A'' = {{overline|''A''}} + 1}}. 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 ''B<sub>i</sub>'' thus yielding the following output functions: * 0 (with both the ''A<sub>i</sub>'' and ''B<sub>i</sub>'' inputs set to zero and {{nowrap|1=''D'' = 0}}) * 1 (with both the ''A<sub>i</sub>'' and ''B<sub>i</sub>'' inputs set to zero and {{nowrap|1=''D'' = 1}}) * ''A'' (with the ''B<sub>i</sub>'' input set to zero) * ''B'' (with the ''A<sub>i</sub>'' input set to zero) * {{nowrap|''A'' + 1}} (with the ''B<sub>i</sub>'' input set to zero and {{nowrap|1=''D'' = 1}}) * {{nowrap|''B'' + 1}} (with the ''A<sub>i</sub>'' input set to zero and {{nowrap|1=''D'' = 1}}) * {{nowrap|''A'' + ''B''}} * {{nowrap|''A'' − ''B''}} * {{nowrap|''B'' − ''A''}} * {{overline|''A''}} (with ''A<sub>i</sub>'' set to invert; ''B<sub>i</sub>'' set to zero; and {{nowrap|1=''D'' = 0}}) * −''A'' (with ''A<sub>i</sub>'' set to invert; ''B<sub>i</sub>'' set to zero; and {{nowrap|1=''D'' = 1}}) * {{overline|''B''}} (with ''B<sub>i</sub>'' set to invert; ''A<sub>i</sub>'' set to zero; and {{nowrap|1=''D'' = 0}}) * −''B'' (with ''B<sub>i</sub>'' set to invert; ''A<sub>i</sub>'' set to zero; and {{nowrap|1=''D'' = 1}}) By adding more logic in front of the adder, a single adder can be converted into much more than just an adder—an [[arithmetic logic unit|ALU]]. ==See also== * [[Adder (electronics)]] * [[Carry-lookahead adder]] * [[Carry-save adder]] * [[Adding machine]] * [[Subtractor]] ==References== {{reflist}} {{DEFAULTSORT:Adder-subtractor}} [[Category:Telecommunications equipment]] [[Category:Binary arithmetic]] [[Category:Adders (electronics)]] [[Category:Arithmetic logic circuits]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite news
(
edit
)
Template:Main
(
edit
)
Template:More citations needed
(
edit
)
Template:Nowrap
(
edit
)
Template:Overline
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sidebar arithmetic logic circuits
(
edit
)