Misplaced Pages

Subtractor

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
(Redirected from Half subtractor) Circuit that performs subtraction
This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Subtractor" – news · newspapers · books · scholar · JSTOR (December 2009) (Learn how and when to remove this message)
Part of a series on
Arithmetic logic circuits
Quick navigation
Theory
Components
Categories
See also

In electronics, a subtractor – a digital circuit that performs subtraction of numbers – can be designed using the same approach as that of an adder. The binary subtraction process is summarized below. As with an adder, in the general case of calculations on multi-bit numbers, three bits are involved in performing the subtraction for each bit of the difference: the minuend ( X i {\displaystyle X_{i}} ), subtrahend ( Y i {\displaystyle Y_{i}} ), and a borrow in from the previous (less significant) bit order position ( B i {\displaystyle B_{i}} ). The outputs are the difference bit ( D i {\displaystyle D_{i}} ) and borrow bit B i + 1 {\displaystyle B_{i+1}} . The subtractor is best understood by considering that the subtrahend and both borrow bits have negative weights, whereas the X and D bits are positive. The operation performed by the subtractor is to rewrite X i Y i B i {\displaystyle X_{i}-Y_{i}-B_{i}} (which can take the values -2, -1, 0, or 1) as the sum 2 B i + 1 + D i {\displaystyle -2B_{i+1}+D_{i}} .

D i = X Y i B i {\displaystyle D_{i}=X_{}\oplus Y_{i}\oplus B_{i}}
B i + 1 = X i < ( Y i + B i ) {\displaystyle B_{i+1}=X_{i}<(Y_{i}+B_{i})} ,

where ⊕ represents exclusive or.

Subtractors are usually implemented within a binary adder for only a small cost when using the standard two's complement notation, by providing an addition/subtraction selector to the carry-in and to invert the second operand.

B = B ¯ + 1 {\displaystyle -B={\bar {B}}+1} (definition of two's complement notation)
A B = A + ( B ) = A + B ¯ + 1 {\displaystyle {\begin{alignedat}{2}A-B&=A+(-B)\\&=A+{\bar {B}}+1\\\end{alignedat}}}

Half subtractor

Figure 1: Logic diagram for a half subtractor

The half subtractors can be designed through the combinational Boolean logic circuits as shown in Figure 1 and 2.The half subtractor is a combinational circuit which is used to perform subtraction of two bits. It has two inputs, the minuend X {\displaystyle X} and subtrahend Y {\displaystyle Y} and two outputs the difference D {\displaystyle D} and borrow out B out {\displaystyle B_{\text{out}}} . The borrow out signal is set when the subtractor needs to borrow from the next digit in a multi-digit subtraction. That is, B out = 1 {\displaystyle B_{\text{out}}=1} when X < Y {\displaystyle X<Y} . Since X {\displaystyle X} and Y {\displaystyle Y} are bits, B out = 1 {\displaystyle B_{\text{out}}=1} if and only if X = 0 {\displaystyle X=0} and Y = 1 {\displaystyle Y=1} . An important point worth mentioning is that the half subtractor diagram aside implements X Y {\displaystyle X-Y} and not Y X {\displaystyle Y-X} since B out {\displaystyle B_{\text{out}}} on the diagram is given by

B out = X ¯ Y {\displaystyle B_{\text{out}}={\overline {X}}\cdot Y} .

This is an important distinction to make since subtraction itself is not commutative, but the difference bit D {\displaystyle D} is calculated using an XOR gate which is commutative.

Half-subtractor using NAND gate only.
Figure 2: Half-subtractor using NAND gate only.

The truth table for the half subtractor is:

Inputs Outputs
X Y D Bout
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0

Using the table above and a Karnaugh map, we find the following logic equations for D {\displaystyle D} and B out {\displaystyle B_{\text{out}}} :

D = X Y {\displaystyle D=X\oplus Y}
B out = X ¯ Y {\displaystyle B_{\text{out}}={\overline {X}}\cdot Y} .

Consequently, a simplified half-subtract circuit, advantageously avoiding crossed traces in particular as well as a negate gate is:

      X ── XOR ─┬─────── |X-Y|,  is 0 if X equals Y, 1 otherwise
         ┌──┘   └──┐  
      Y ─┴─────── AND ── borrow, is 1 if Y > X, 0 otherwise

where lines to the right are outputs and others (from the top, bottom or left) are inputs.

Full subtractor

The full subtractor is a combinational circuit which is used to perform subtraction of three input bits: the minuend X {\displaystyle X} , subtrahend Y {\displaystyle Y} , and borrow in B in {\displaystyle B_{\text{in}}} . The full subtractor generates two output bits: the difference D {\displaystyle D} and borrow out B out {\displaystyle B_{\text{out}}} . B in {\displaystyle B_{\text{in}}} is set when the previous digit is borrowed from X {\displaystyle X} . Thus, B in {\displaystyle B_{\text{in}}} is also subtracted from X {\displaystyle X} as well as the subtrahend Y {\displaystyle Y} . Or in symbols: X Y B in {\displaystyle X-Y-B_{\text{in}}} . Like the half subtractor, the full subtractor generates a borrow out when it needs to borrow from the next digit. Since we are subtracting Y {\displaystyle Y} and B in {\displaystyle B_{\text{in}}} from X {\displaystyle X} , a borrow out needs to be generated when X < Y + B in {\displaystyle X<Y+B_{\text{in}}} . When a borrow out is generated, 2 is added in the current digit. (This is similar to the subtraction algorithm in decimal. Instead of adding 2, we add 10 when we borrow.) Therefore, D = X Y B in + 2 B out {\displaystyle D=X-Y-B_{\text{in}}+2B_{\text{out}}} .

The truth table for the full subtractor is:

Inputs Outputs
X Y Bin D Bout
0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 0 1
1 0 0 1 0
1 0 1 0 0
1 1 0 0 0
1 1 1 1 1

Therefore the equation is:

D = X Y B i n {\displaystyle D=X\oplus Y\oplus B_{in}}

B o u t = X ¯ B i n + X ¯ Y + Y B i n {\displaystyle B_{out}={\bar {X}}B_{in}+{\bar {X}}Y+YB_{in}}

See also

References

  1. Foundations Of Digital Electronics by Elijah Mwangi
  2. Beltran, A.A., Nones, K., Salanguit, R.L., Santos, J.B., Santos, J.M., & Dizon, K.J. (2021). Low Power NAND Gate–based Half and Full Adder / Subtractor Using CMOS Technique.

External links

Processor technologies
Models
Architecture
Instruction set
architectures
Types
Instruction
sets
Execution
Instruction pipelining
Hazards
Out-of-order
Speculative
Parallelism
Level
Multithreading
Flynn's taxonomy
Processor
performance
Types
By application
Systems
on chip
Hardware
accelerators
Word size
Core count
Components
Functional
units
Logic
Registers
Control unit
Datapath
Circuitry
Power
management
Related
Categories: