Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Adder–subtractor
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
==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}}.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Adder–subtractor
(section)
Add topic