Professional Documents
Culture Documents
Pert7 Subtractor
Pert7 Subtractor
Overview
Binary Subtraction
2s complement Extension to rs complement Subtraction with complements
Binary Adders/Subtractors
Signed numbers Signed Addition/Subtraction Overflow problem
Binary Multipliers
9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 2
Binary Subtraction
Unsigned numbers: minus sign is not explicitly represented. Given 2 binary numbers M and N, find M-N:
Case I: M N, thus, MSB of Borrow is 0 B000110 M 1 1110 30 N -1 0 0 1 1 -19 Result is Correct Dif 0 1 0 1 1 11 Case II: N > M, thus MSB of Borrow is 1 B11 1000 M 1001 1 19 N -1 1 1 1 0 -30 Result requires correction! Dif 1 0 1 0 1 21
9-Apr-10
Binary Subtraction (cont.) In general, if N > M, Dif = M-N+2 , where n = # bits. In Case II of the previous example, Dif= 5 19-30+2 = 21. To correct the magnitude of Dif, which n n should be N-M, calculate 2 -(M-N+2 ). This is known as the 2s complement of Dif.
9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 4
4-bit Subtractor Enabled when B=1; otherwise, just pass the result from the subtractor Selective 2s Complementer
Binary Adder
4-bit Subtractor
Selective 2s Complementer
Sub/Add
Result 9-Apr-10
We examine only 2s and 1s complements for base 2. Same concepts hole for other bases (ex. decimal).
9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 9
2s Complement
For a positive n digit number N2 in binary, the 2's complement, 2C(N2), is given by:
2C(N2) =
2n-N2 , 0 ,
if n > 0 if n = 0
Example: N2 =1010
2C(N2) = 24-N2 = 100002 10102 = 01102
Example: N2 =11111
2C(N2) = 25-N2 = 1000002 111112 = 00001 2
9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 10
2s Complement (cont.)
Heres an easier way to compute the 2s complement:
1. Leave all least significant 0s and first 1 unchanged. 2. Replace 0 with 1 and 1 with 0 in all remaining higher significant bits.
Examples:
complement unchanged complement unchanged
N = 1010 01 10 2s complement
9-Apr-10
1s Complement
For a positive n digit number N2 in binary, the 1's complement, 1C(N2), is given by:
1C(N2) = (2n-1) - N2
Example: N2 =011
1C(N2) = (23-1)-N2 = 1112 0112 = 1002 1C(N2) = (24-1) - N2 = 11112 10102 = 0101 2
Example: N2 =1010
Observation: 1s complement can be derived by just complementing all the bits in the number.
9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 12
Thus, the 2s complement can be obtained by deriving the 1s complement and adding 1 to it. Example:
N = 1001 2C(N) = 24 N = 10000 1001 = 0111 1C(N) = 24 1 - N = 1111 1001 = 0110 2C(N) = 1C(N) + 1 = 0110 + 0001 = 0111
9-Apr-10
13
Subtraction with Complements To perform M-N = M+(-N), we may use a complement form to represent the negative number -N, and perform a plain old addition. Need to be able to convert the result.
9-Apr-10
14
Find R = B-A:
2C(A) = 0101100 (4410) B+A = 1000011+0101100 = 1101111 R = -2C(B+A) = -0010001 (-17)
9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 16
Example
Find R = B-A:
1C(A) = 0101011 B+A = 1000011+0101011 = 1101110 R = -1C(B+A) = -0010001 (-17)
9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 18
Binary Adder/Subtractors
If we perform subtraction using complements, we eliminate the subtraction operation, and thus, can use an adder with appropriate complementer for subtraction. Actually, we can use an adder for both addition and subtraction:
Complement subtrahend for subtraction Do not complement subtrahend for addition
Thus, to form an adder-subtractor circuit, we only need a selective complementer and an adder.
9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 19
9-Apr-10
20
XOR
9-Apr-10
9-Apr-10
22
B3
B2
B1
B0 0
B3
B2
B1
B0 1
9-Apr-10
25
Signed Binary Numbers Signed-magnitude system: Singed numbers are represented using the MSB of the binary number to indicate the numbers sign:
If MSB is 0 number is positive If MSB is 1 number is negative
9-Apr-10
26
Another example:
10112 is
1110 in unsigned -310 in signed
9-Apr-10
27
Signed Binary Numbers (cont.) To implement signed-magnitude addition and subtraction we need to separate the sing bit from the magnitude bits, and treat the magnitude bits as an unsigned number (do correction whenever necessary). To avoid correction, use the singedcomplement system.
9-Apr-10
28
Signed-Complement System
The magnitude of the negative number is represented in a complement form (2s or 1s complement). Ex.: Use 8-bits to represent -910 and 910
-910 is:
10010012 in singed-magnitude 111101102 in singed-1s complement 111101112 in singed-2s complement
Signed-Magnitude Addition-Subtraction
To perform addition or subtraction of two numbers M and N in signed-magnitude, follow ordinary arithmetic rules:
Same signs: Add and keep same sign. Different signs: Subtract N from M; if end Borrow is 1, correct result by taking its 2s complement. Sign is negative. Example: M:00011001, N:10100101 N is negative, so find |M-N|=0011001-0100101 =1110100, with end borrow 1. This implies that M-N is a negative number, so to correct find its 2s complement 0001100. Result is 10001100.
9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 30
Signed-Complement Addition
Addition of two signed numbers, with negative ones represented in signed-2s complement, is obtained by adding the two numbers (including the sing bits). Carry out is discarded. Examples: (Assume 5-bit representations)
01010 (+10) 01010 (+10) 10110 (-10) +00101 (+5) +11011 (-5) +00101 (+5) 01111 (+15) 00101 (+5) 11011 (-5) 10110 (-10) +11011 (-5) 10001 (-15)
9-Apr-10
31
Signed-Complement Subtraction
Subtraction of two signed numbers, with negative ones represented in signed-2s complement, is obtained by taking the 2s complement of the subtrahend (including sing bit) and add it to the minuend. Discard carry out. Examples: (Assume 5-bit representations)
01010 (+10) -00101 -(+5) 01010 (+10) +11011 +(-5) 00101 (+5) 01010 (+10) 10110 (-10) 10110 (-10) -11011 -(-5) -00101 -(+5) -11011 -(-5) 01010 (+10) +00101 +(+5) 01111 (+15) 10110 (-10) +11011 +(-5) 10001 (-15) 10110 (-10) +00101 +(+5) 11011 (-5)
9-Apr-10
33
The Overflow problem If the sum of two n-bit numbers results in an n+1 number, then an overflow conditions is said to occur. Detection of overflow can be implemented using either hardware or software. Detection depends on number system used: signed or unsigned.
9-Apr-10
34
Subtraction:
Can never occur. Magnitude of the result is always equal or smaller than the larger of the two numbers.
9-Apr-10
35
V C Cn
Cn+1
n-bit Adder/Subtractor
C =1 indicates overflow condition when adding/subtr. unsigned numbers. V=1 indicates overflow condition when adding/subtr. signed-2s complement numbers 9-Apr-10
Chapter 3-v: Combinational Logic Design (3.9-3.11) 38
9-Apr-10
40
Half Adders are Sufficient since there is no Carry-in in addition to the two inputs to sum
9-Apr-10
41
9-Apr-10
42