Logic and Computer Design Fundamentals Adders and Multiplication 24 Pearson Education, Inc.
Overview Iterative combinational circuits Binary adders Half and full adders Ripple carry and carry lookahead adders Binary subtraction Binary multiplication Other arithmetic functions Chapter 5 2
Enabling Function Enabling permits an input signal to pass through to an output Disabling blocks an input signal from passing through to an output, replacing it with a fixed value The value on the output when it is disable can be Hi-Z (as for three-state buffers and X transmission gates),, or F When disabled, output When disabled, output See Enabling App in text EN EN X (a) F (b) Chapter 5 3
Decoding Decoding - the conversion of an n-bit input code to an m-bit output code with n m 2 n such that each valid code word produces a unique output code Circuits that perform decoding are called decoders Here, functional blocks for decoding are called n-to-m line decoders, where m 2 n, and generate 2 n (or fewer) minterms for the n input variables Chapter 5 4
Decoder Examples -to-2-line Decoder 2-to-4-Line Decoder A D D A (a) A (b) D 5 A D 5 A A A D D D 2 D 3 A D 5 A A D 5 A A (a) Note that the 2-4-line made up of 2 -to-2- line decoders and 4 AND gates. (b) D 2 5 A A D 3 5 A A Chapter 5 5
Decoder Expansion General procedure given in book for any decoder with n inputs and 2 n outputs. This procedure builds a decoder backward from the outputs. The output AND gates are driven by two decoders with their numbers of inputs either equal or differing by. These decoders are then designed using the same procedure until 2-to--line decoders are reached. The procedure can be modified to apply to decoders with the number of outputs 2 n Chapter 5 6
Decoder Expansion - Example 3-to-8-line decoder Number of output ANDs = 8 Number of inputs to decoders driving output ANDs = 3 Closest possible split to equal 2-to-4-line decoder -to-2-line decoder 2-to-4-line decoder Number of output ANDs = 4 Number of inputs to decoders driving output ANDs = 2 Closest possible split to equal Two -to-2-line decoders See next slide for result Chapter 5 7
Decoder Expansion - Example Result 4 2-input ANDs 8 2-input ANDs A D D A D 2 2-to-4-Line decoder D 3 D 4 A 2 D 5 -to-2-line decoders D 6 D 7 3-to-8 Line decoder Chapter 5 8
Decoder Expansion - Example 2 7-to-28-line decoder Number of output ANDs = 28 Number of inputs to decoders driving output ANDs = 7 Closest possible split to equal 4-to-6-line decoder 3-to-8-line decoder 4-to-6-line decoder Number of output ANDs = 6 Number of inputs to decoders driving output ANDs = 2 Closest possible split to equal 2 2-to-4-line decoders Complete using known 3-8 and 2-to-4 line decoders Chapter 5 9
Decoder with Enable In general, attach m-enabling circuits to the outputs See truth table below for function Note use of X s to denote both and Combination containing two X s represent four binary combinations Alternatively, can be viewed as distributing value of signal EN EN to of 4 outputs A In this case, called a demultiplexer A D EN A A D D D 2 D 3 D X X D 2 D 3 (a) (b) Chapter 5
Encoding Encoding - the opposite of decoding - the conversion of an m-bit input code to a n-bit output code with n m 2 n such that each valid code word produces a unique output code Circuits that perform encoding are called encoders An encoder has 2 n (or fewer) input lines and n output lines which generate the binary code corresponding to the input values Typically, an encoder converts a code containing exactly one bit that is to a binary code corresponding to the position in which the appears. Chapter 5
Encoder Example A decimal-to-bcd encoder Inputs: bits corresponding to decimal digits through 9, (D,, D 9 ) Outputs: 4 bits with BCD codes Function: If input bit D i is a, then the output (A 3, A 2, A, A ) is the BCD code for i, The truth table could be formed, but alternatively, the equations for each of the four outputs can be obtained directly. Chapter 5 2
Encoder Example (continued) Input D i is a term in equation A j if bit A j is in the binary value for i. Equations: A 3 = D 8 + D 9 A 2 = D 4 + D 5 + D 6 + D 7 A = D 2 + D 3 + D 6 + D 7 A = D + D 3 + D 5 + D 7 + D 9 F = D 6 + D 7 can be extracted from A 2 and A Is there any cost saving? Chapter 5 3
Priority Encoder If more than one input value is, then the encoder just designed does not work. One encoder that can accept all possible combinations of input values and produce a meaningful result is a priority encoder. Among the s that appear, it selects the most significant input position (or the least significant input position) containing a and responds with the corresponding binary code for that position. Chapter 5 4
Priority Encoder Example Priority encoder with 5 inputs (D 4, D 3, D 2, D, D ) - highest priority to most significant present - Code outputs A2, A, A and V where V indicates at least one present. No. of Minterms/Row D4 D3 D2 D D A2 A A Inputs Outputs V 2 4 8 X X X X X X X X X 6 X X X X Xs in input part of table represent or ; thus table entries correspond to product terms instead of minterms. The column on the left shows that all 32 minterms are present in the product terms in the table Chapter 5 5
Priority Encoder Example (continued) Could use a K-map to get equations, but can be read directly from table and manually optimized if careful: A 2 = D 4 A = D 4 D 3 + D 4 D 3 D 2 = D 4 F, F = (D 3 + D 2 ) A = D 4 D 3 + D 4 D 3 D 2 D = D 4 (D 3 + D 2 D) V = D 4 + F + D + D Chapter 5 6
Iterative Combinational Circuits Arithmetic functions Operate on binary vectors Use the same subfunction in each bit position Can design functional block for subfunction and repeat to obtain functional block for overall function Cell - subfunction block Iterative array - a array of interconnected cells An iterative array can be in a single dimension (D) or multiple dimensions Chapter 5 7
Block Diagram of a D Iterative Array A n- B n- A B A B X n X n- Y n- X 2 Y 2 Cell n- Cell Y n X Y Cell X Y C n- Example: n = 32 Number of inputs =? Truth table rows =? Equations with up to? input variables Equations with huge number of terms Design impractical! Iterative array takes advantage of the regularity to make design feasible C C Chapter 5 8
Functional Blocks: Addition Binary addition used frequently Addition Development: Half-Adder (HA), a 2-input bit-wise addition functional block, Full-Adder (FA), a 3-input bit-wise addition functional block, Ripple Carry Adder, an iterative array to perform binary addition, and Carry-Look-Ahead Adder (CLA), a hierarchical structure to improve performance. Chapter 5 9
Functional Block: Half-Adder A 2-input, -bit width binary adder that performs the following computations: X + Y + + + + C S A half adder adds two bits to produce a two-bit sum The sum is expressed as a X Y C S sum bit, S and a carry bit, C The half adder can be specified as a truth table for S and C Chapter 5 2
Logic Simplification: Half-Adder The K-Map for S, C is: This is a pretty trivial map! By inspection: S X Y 2 3 C X Y 2 3 S S = = X (X Y + X Y = X + Y) (X + Y) Y and C = X Y C = ( ( X Y ) ) Chapter 5 2
Implementations: Half-Adder The most common half adder implementation is: X Y S (e) S = X Y C = X Y C A NAND only implementation is: S = (X C = ( + Y) C ) ( X Y) X C S Y Chapter 5 22
Functional Block: Full-Adder A full adder is similar to a half adder, but includes a carry-in bit from lower stages. Like the half-adder, it computes a sum bit, S and a carry bit, C. For a carry-in (Z) of, it is the same as the half-adder: For a carry- in (Z) of : Z X + Y + + + + C S Z X + Y + + + + C S Chapter 5 23
Logic Optimization: Full-Adder Full-Adder Truth Table: Full-Adder K-Map: X Y Z C S S Y C Y X 3 2 4 5 7 6 X 3 2 4 5 7 6 Z Z Chapter 5 24
Equations: Full-Adder From the K-Map, we get: S = X Y Z + X Y Z + X Y Z + C = X Y + X Z + Y Z The S function is the three-bit XOR function (Odd Function): S = The Carry bit C is if both X and Y are (the sum is 2), or if the sum is and a carry-in (Z) occurs. Thus C can be re-written as: C = X X Y Y + (X The term X Y is carry generate. The term X Y is carry propagate. Z Y) Z X Y Z Chapter 5 25
Implementation: Full Adder Full Adder Schematic Here X, Y, and Z, and C (from the previous pages) are A, B, C i and C o, respectively. Also, G = generate and P = propagate. Note: This is really a combination of a 3-bit odd function (for S)) and Carry logic (for C o ): (G = Generate) OR (P =Propagate AND C i = Carry In) Co = G + P Ci C i+ G i A i B i S i P i C i Chapter 5 26
Binary Adders To add multiple operands, we bundle logical signals together into vectors and use functional blocks that operate on the vectors Example: 4-bit ripple carry adder: Adds input vectors A(3:) and B(3:) to get a sum vector S(3:) Note: carry out of cell i becomes carry in of cell i + Description Subscript 3 2 Name Carry In C i Augend A i Addend B i Sum S i Carry out C i+ Chapter 5 27
4-bit Ripple-Carry Binary Adder A four-bit Ripple Carry Adder made from four -bit Full Adders: B 3 A 3 B 2 A 2 B A B A FA C 3 C 2 C FA FA FA C C 4 S 3 S 2 S S Chapter 5 28
Carry Propagation & Delay One problem with the addition of binary numbers is the length of time to propagate the ripple carry from the least significant bit to the most significant bit. The gate-level propagation path for a 4-bit ripple carry adder of the last example: A 3 B3 A 2 A A B 2 B B C 3 C 2 C C C 4 S 3 S 2 S S Note: The "long path" is from A or B though the circuit to S 3. Chapter 5 29
Carry Lookahead Given Stage i from a Full Adder, we know that there will be a carry generated when A i = B i = "", whether or not there is a carry-in. A i B i Alternately, there will be G i a carry propagated if the half-sum is "" and a carry-in, C i occurs. These two signal conditions P i are called generate, denoted as G i, and propagate, denoted as P i respectively and are identified in the circuit: C i+ S i C i Chapter 5 3
Carry Lookahead (continued) In the ripple carry adder: Gi, Pi, and Si are local to each cell of the adder Ci is also local each cell In the carry lookahead adder, in order to reduce the length of the carry chain, Ci is changed to a more global function spanning multiple cells Defining the equations for the Full Adder in term of the P i and G i : P i = A B G = Ai Bi S = G + P i i i i = Pi Ci Ci+ i i C i Chapter 5 3
Carry Lookahead Development C i+ can be removed from the cells and used to derive a set of carry equations spanning multiple cells. Beginning at the cell with carry in C : C = G + P C C 2 = G + P C = G + P (G + P C ) = G + P G + P P C C 3 = G 2 + P 2 C 2 = G 2 + P 2 (G + P G + P P C ) = G 2 + P 2 G + P 2 P G + P 2 P P C C 4 = G 3 + P 3 C 3 = G 3 + P 3 G 2 + P 3 P 2 G + P 3 P 2 P G + P 3 P 2 P P C Chapter 5 32
Chapter 5 33 Group Carry Lookahead Logic Figure 5-6 in the text shows shows the implementation of these equations for four bits. This could be extended to more than four bits; in practice, due to limited gate fan-in, such extension is not feasible. Instead, the concept is extended another level by considering group generate (G -3 ) and group propagate (P -3 ) functions: Using these two equations: Thus, it is possible to have four 4-bit adders use one of the same carry lookahead circuit to speed up 6-bit addition 2 3 3 2 3 2 3 2 3 3 3 P P P P P G P P P P G P P G P G G = + + + = 3 3 4 C P G C + =
Carry Lookahead Example Specifications: 6-bit CLA Delays: NOT = XOR = Isolated AND = 3 AND-OR = 2 Longest Delays: 3 CLA CLA CLA CLA 2 CLA Ripple carry adder* = 3 + 5 2 + 3 = 36 CLA = 3 + 3 2 + 3 = 2 2 2 3 *See slide 6 Chapter 5 34
Unsigned Subtraction Algorithm: Subtract the subtrahend N from the minuend M If no end borrow occurs, then M N, and the result is a non-negative number and correct. If an end borrow occurs, the N > M and the difference M N + 2n is subtracted from 2n, and a minus sign is appended to the result. ( ) Examples: Chapter 5 35
Unsigned Subtraction (continued) The subtraction, 2 n N, is taking the 2 s complement of N To do both unsigned addition and unsigned A subtraction requires: Quite complex! Goal: Shared simpler logic for both addition and subtraction Introduce complements as an approach Binary adder Subtract/Add S Borrow Complement Quadruple 2-to- multiplexer B Binary subtractor Selective 2's complementer Result Chapter 5 36
Binary 2's Complement For r = 2, N = 2, n = 8 (8 digits), we have: (r n ) = 256 or 2 The 2's complement of is then: Note the result is the 's complement plus, a fact that can be used in designing hardware Chapter 5 37
Subtraction with 2 s Complement For n-digit, unsigned numbers M and N, find M N in base 2: Add the 2's complement of the subtrahend N to the minuend M: M + (2 n N) = M N + 2 n If M > N, the sum produces end carry r n which is discarded; from above, M N remains. If M < N, the sum does not produce an end carry and, from above, is equal to 2 n ( N M ), the 2's complement of ( N M ). To obtain the result (N M), take the 2's complement of the sum and place a to its left. Chapter 5 38
Unsigned 2 s Complement Subtraction Example Find 2 2 2 s comp + The carry of indicates that no correction of the result is required. Chapter 5 39
2 s Complement Adder/Subtractor Subtraction can be done by addition of the 2's Complement.. Complement each bit ('s Complement.) 2. Add to the result. The circuit shown computes A + B and A B: For S =, subtract, the 2 s complement B 3 of B is formed by using XORs to form the s comp and adding the applied to C. For S =, add, B is C 3 passed through unchanged C 4 S 3 A 3 B 2 A 2 B A B A C 2 C C FA FA FA FA S 2 S S S Chapter 5 4
Overflow Detection Overflow occurs if n + bits are required to contain the result from an n-bit addition or subtraction Overflow can occur for: Addition of two operands with the same sign Subtraction of operands with different signs Signed number overflow cases with correct result sign + + Detection can be performed by examining the result signs which should match the signs of the top operand Chapter 5 4
Overflow Detection Signed number cases with carries C n and C n shown for correct result signs: + + Signed number cases with carries shown for erroneous result signs (indicating overflow): + + Simplest way to implement overflow V = C n + C n This works correctly only if s complement and the addition of the carry in of is used to implement the complementation! Otherwise fails for... Chapter 5 42
Binary Multiplication The binary digit multiplication table is trivial: (a b) b = b = a = a = This is simply the Boolean AND function. Form larger products the same way we form larger products in base. Chapter 5 43
Review - Decimal Example: (237 49) Partial products are: 237 9, 237 4, and 237 Note that the partial product summation for n digit, base numbers requires adding up to n digits (with carries). Note also n m digit multiply generates up to an m + n digit result. 2 3 7 4 9 2 3 3 9 4 8 - + 2 3 7 - - 3 5 3 3 Chapter 5 44
Binary Multiplication Algorithm We execute radix 2 multiplication by: Computing partial products, and Justifying and summing the partial products. (same as decimal) To compute partial products: Multiply the row of multiplicand digits by each multiplier digit, one at a time. With binary numbers, partial products are very simple! They are either: all zero (if the multiplier digit is zero), or the same as the multiplicand (if the multiplier digit is one). Note: No carries are added in partial product formation! Chapter 5 45
Example: ( x ) Base 2 Partial products are:,, and Note that the partial product summation for n digit, base 2 numbers requires adding up to n digits (with carries) in a column. Note also n m digit multiply generates up to an m + n digit result (same as decimal). Chapter 5 46
Multiplier Boolean Equations We can also make an n m block multiplier and use that to form partial products. Example: 2 2 The logic equations for each partial-product binary digit are shown below: We need to "add" the columns to get the product bits P, P, P2, and P3. Note that some columns may generate carries. b b a a (a. b ) (a. b ) + (a. b ) (a. b ) P 3 P 2 P P Chapter 5 47
Multiplier Arrays Using Adders An implementation of the 2 2 A multiplier array is shown: B B A B B HA HA C 3 C 2 C C Chapter 5 48
Multiplier Using Wide Adders A more structured way to develop an n m multiplier is to sum partial products using adder trees The partial products are formed using an n m array of AND gates Partial products are summed using m adders of width n bits Example: 4-bit by 3-bit adder Text figure 5- shows a 4 3 = 2 element array of AND gates and two 4-bit adders Chapter 5 49
Cellular Multiplier Array Another way to implement multipliers is to use an n m cellular array structure of uniform elements as shown: Each element computes a single bit product equal to a i b j, and implements a single bit full adder Column Sum from above Cell [ j, k ] pp [ j, k ] Carry [ j, k ] AB Co Ci FA S b[ k ] Column Sum to below a[ j ] Carry [ j, (k - )] Chapter 5 5
Other Arithmetic Functions Convenient to design the functional blocks by contraction - removal of redundancy from circuit to which input fixing has been applied Functions Incrementing Decrementing Multiplication by Constant Division by Constant Zero Fill and Extension Chapter 5 5
Design by Contraction Contraction is a technique for simplifying the logic in a functional block to implement a different function The new function must be realizable from the original function by applying rudimentary functions to its inputs Contraction is treated here only for application of s and s (not for X and X) After application of s and s, equations or the logic diagram are simplified by using rules given on pages 224-225 of the text. Chapter 5 52
Design by Contraction Example Contraction of a ripple carry adder to incrementer for n = 3 Set B = C 3 5 X X X A 2 A A 4 5 2 C 3 C 5 S 2 S S (a) A 2 A A S 2 S S (b) The middle cell can be repeated to make an incrementer with n > 3. Chapter 5 53
Incrementing & Decrementing Incrementing Adding a fixed value to an arithmetic variable Fixed value is often, called counting (up) Examples: A +, B + 4 Functional block is called incrementer Decrementing Subtracting a fixed value from an arithmetic variable Fixed value is often, called counting (down) Examples: A, B 4 Functional block is called decrementer Chapter 5 54
Multiplication/Division by 2 n (a) Multiplication by Shift left by 2 (b) Division by Shift right by 2 Remainder preserved C 5 B 3 C 3 C 4 B 2 C 2 B 3 B 2 B B C 3 B C (a) C 2 C C B C C 2 C 2 2 (b) Chapter 5 55
Multiplication by a Constant Multiplication of B(3:) by See text Figure 53 (a) for contraction B 3 B 2 B B B 3 B 2 B B Carry output 4-bit Adder Sum C 6 C 5 C 4 C 3 C 2 C C Chapter 5 56
Zero Fill Zero fill - filling an m-bit operand with s to become an n-bit operand with n > m Filling usually is applied to the MSB end of the operand, but can also be done on the LSB end Example: filled to 6 bits MSB end: LSB end: Chapter 5 57
Extension Extension - increase in the number of bits at the MSB end of an operand by using a complement representation Copies the MSB of the operand into the new positions Positive operand example - extended to 6 bits: Negative operand example - extended to 6 bits: Chapter 5 58
Terms of Use 24 by Pearson Education,Inc. All rights reserved. The following terms of use apply in addition to the standard Pearson Education Legal Notice. Permission is given to incorporate these materials into classroom presentations and handouts only to instructors adopting Logic and Computer Design Fundamentals as the course text. Permission is granted to the instructors adopting the book to post these materials on a protected website or protected ftp site in original or modified form. All other website or ftp postings, including those offering the materials for a fee, are prohibited. You may not remove or in any way alter this Terms of Use notice or any trademark, copyright, or other proprietary notice, including the copyright watermark on each slide. Return to Title Page Chapter 5 59