Download Chapter 2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Canonical normal form wikipedia , lookup

Addition wikipedia , lookup

Transcript
Chapter 5
Arithmetic Functions and Circuits
5-3 Binary Substraction
1. Subtract the subtrahend N from the minuend M.
2. If no end borrow occurs, then M >= N, and the result is
nonnegative and correct.
3. If an end borrow occurs, then N > M, and the
difference, M – N + 2n, is subtracted from 2n, and a
minus sign is appended to the result.
Example 5-1
Unsigned Binary Subtraction by 2’s Complement
Subtract
The block diagram for a 4-bit adder-subtractor using these
functional blocks is shown in Figure 5-7.
chap_5-2_c150
Arithmetic Functions and Circuits
Page 1 of 10
Figure 5-7
Block Diagram of Binary Adder-Subtractor
Complements
 The 1’s complement of 000111 is 1110000.
 In similar fashion, the 9’s complement of a hexadecimal
number are obtained by subtracting each digit from 9,
7, and F (decimal 15), respectively.
 The 2’s complement can be formed by leaving all least
significant 0’s with 1’s in all other higher significant bits.
 Thus, the 2’s complement of 1101100 is 0010100 and
is obtained by leaving the two low-order 0’s and the first
1 unchanged and then replacing 1’s with 0’s and 0’s
with 1’s in the other four most significant bits.
chap_5-2_c150
Arithmetic Functions and Circuits
Page 2 of 10
 In other bases, the first non-zero digit is subtracted from
the base r, and the remaining digits to the left are
replaced with r-1 minus their values.
Subtraction with Complements
Example 5-2
 Given the two binary numbers X = 1010100 and Y =
1000011, perform the subtraction X – Y and Y – X
using 2’s complement operations.
 We have
 Subtraction of unsigned numbers also can be done by
means of the 1’s complement.
 Remember that the 1’s complement is one less than the
2’s complement.
 Because of this, the result of adding the minuend to the
complement of the subtrahend produces a sum that is
one less than the correct difference when an end carry
occurs.
 Discarding the end carry and adding one to the sum is
referred to as an end-around-carry.
chap_5-2_c150
Arithmetic Functions and Circuits
Page 3 of 10
Example 5-3
Unsigned Binary Subtraction by 1’s Complement Addition
5-4 Binary Adder-Subtractors
 Using either the 2’s or 1’s complement, we have
eliminated the subtraction operation and need only the
appropriate complementer and an adder.
 When performing a subtraction we complement the
subtrahend N, and when performing an addition we do
not complement N.
 These operations can be accomplished to form an
adder-subtractor,
 We have used 2’s complement, since it is most
prevalent in modern systems.
 The 2’s complement can be obtained by taking the 1’s
complement and adding 1 to the least significant bit.
chap_5-2_c150
Arithmetic Functions and Circuits
Page 4 of 10
Signed Binary Numbers
 Positive integers and the number zero can be
represented as unsigned numbers.
 To represent negative integers, we need a notation for
negative values.
 0 ----- for positive numbers.
 1 ----- for negative numbers.
 If the binary number is signed, then the leftmost bit
represents the sign and the rest of the bits represent
the number.
 If the binary is assumed to be unsigned, then the
leftmost bit is the most significant bit of the number.
 For example:
o 01001 ----- can be considered as 9
(unsigned binary)
o 11001 ----- binary equivalent of 25 when
considered as a signed number
 or -9 when considered as a signed number.
chap_5-2_c150
Arithmetic Functions and Circuits
Page 5 of 10
 Because the 1 in the leftmost position
designates a minus sign and the remaining
four bits represent binary 9.
 Although there is only one way to represent +9, we
have three different ways to represent -9 using eight
bits:
o In signed-magnitude representation:
10001001
o In signed-1’s complement representation:
11110110
o In signed-2’s complement representation:
11110111
 In signed magnitude, -9 is obtained from +9 by
changing the sign bit in the leftmost position from 0 to 1.
 In signed 1’s complement, -9 is obtained by
complementing all the bits of +9, including the sign bit.
 The 2’s complement representation of -9 is obtained by
taking the 2’s complement of the position number,
including the 0 sign bit.
chap_5-2_c150
Arithmetic Functions and Circuits
Page 6 of 10
Signed Binary Addition and Subtraction
Overflow
 Overflow is a problem in computers because the
number of bits that hold a number is fixed, and a result
chap_5-2_c150
Arithmetic Functions and Circuits
Page 7 of 10
that exceeds the number of bits cannot be
accommodated.
 Simple logic that provides overflow detection is shown
in Figure 5-9.
 If the numbers are considered unsigned, then the C
output being equal to 1 detects a carry (an overflow) for
an addition and indicates that no correction step is
required for a subtraction.
 C being equal to 0 detects no carry (no overflow) for an
addition and indicates that a correction step is required
for a subtraction.
Figure 5-9
Overflow Detection Logic for Addition and Subtraction
5-5 Binary Multiplication
 Multiplication of binary numbers is performed in the
same way as with decimal numbers.
 The multiplicand is multiplied by each bit of the
multiplier, starting from the least significant bit.
 Each such multiplication forms a partial product.
 Successive partial products are shifted one bit to the
left.
 The final product is obtained from the sum of the partial
products.
chap_5-2_c150
Arithmetic Functions and Circuits
Page 8 of 10
Figure 5-10
A 2-Bit by 2Bit Binary Multiplier
chap_5-2_c150
Arithmetic Functions and Circuits
Page 9 of 10
Figure 5-11
A 4-Bit by 3-Bit Binary Multiplier
chap_5-2_c150
Arithmetic Functions and Circuits
Page 10 of 10