Download Presentation
## Arithmetic Circuits I

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Iterative Combinational Circuits**• Like a hierachy, except functional blocks per bit**Adders**• Great example of Iterative design • Design a 1-bit adder circuit, then expand to n-bit adder • Look at • Half adder – which is a 2-bit adder • Inputs are bits to be added • Outputs: result and possible carry • Full adder – includes carry in, really a 3-bit adder**Fig. 4-2**Half Adder • S = X Y • C = XY**Full Adder**• Three inputs. Two are operand bits, third is Cin • Two outputs: sum and carry**K Map for S**• What is this? In a half adder the sum bit: S = X Y**K Map for C**In a half adder the carry bit: C = XY**Using two half Adders to Build a Full Adder**• Full adder functions • Half adder functions S = X Y C = XY**Fig. 4-4**Two Half Adders (and an OR)**Ripple-Carry Adder**• Straightforward – connect full adders • C4 : Chain carry-out to carry-in of FA of bits A4 & B4 • C0 in case this is part of larger chain • otherwise just set to zero**Hierarchical 4-Bit Adder**• We can easily use hierarchy here • Design half adder • Use in full adder • Use full adder in 4-bit adder**Binary Subtraction**• Example: • Let M = (19)10 ; N = (30)10 ; How is M-N computed? • In decimal notation: (19)10 – (30)10 = - (11)10 • In binary: (10011)2 - (11110)2 = - (01011)2**Using 2’s & 1’s Complement Representation of Signed**Numbers • People use complemented interpretation for signed numbers • 1’s complement • 2’s complement**1’s Complement**• Given: binary number N with n digits 1’s complement is defined as (2n – 1) - N • Note that (2n – 1) is a number with n bits, all of them 1 • For n = 4, (2n – 1) = (15)10 = 1111**Example: Find 1’s Complement of N =101 1001**• 1’s Complement of N is (2n – 1) - N • Notice that 1’s complement is complement of each bit**2’s Complement**• Given: binary number N with n digits 2’s complement defined as 2n – N for N 0 0 for N = 0 • Note that since 1’s complement is (2n – 1) – N • 2’s complement is just a 1 added to 1’s complement**Example: Find 2’s Complement of N =101 1001**• 2’s Complement of N is 2n - N • To find 2’s complement of N • Find is 1’s complement of N then add 1**Important Property**• Complement of a complement generates original number**Subtraction Using 2s Complement:Compute M-N**• Add 2’s complement of N to M • M + (2n – N) = { M – N + 2n } = F • If M N, this addition will generate a carry, 2n • Discard carry; the result gives the answer of M-N which is positive • If M < N, no carry; M-N is negative; the answer is –(N-M). To compute the answer: • Take 2’s complement of F • 2n – F = 2n - { M – N + 2n } = N-M • Place minus sign in front { - (N-M) }; This is the answer • Hence to compute (M-N): do 1 & 2 if M N; OR 1 & 3 If M < N**1710**Compute M-N;Example 1: M > N • M = (84)10= (101 0100)2 • N = (67)10 = (100 0011)2; • 2’s comp N = ( 011 1100 ) + 1 = 011 1101 M > N; Carry generated; Discard carry; Result is positive M - N**Compute M-N; Example 2: M < N;M =6710 = 100 0011; N = 8410 =**101 0100 • M = 100 0011 minus N = 101 0100 • No end carry • Answer: - (2’s complement of Sum) • Answer: - 0010001 We said numbers are unsigned. What does this mean? How is -1710 represented?**Subtractor**• Compute M-N • Add 2’s complement of N to M: M + (2n – N) • If M >= N, need only “one adder” and a “complementer of N” to do the subtraction. • If M < N, we also need to take 2’s complement of adder’s output to produce magnitude of result 2n -{ M + (2n – N)} = N-M**S is low for add,**high for subtract Inverts each bit of B if S is 1 Add 1 to make 2’s complement Fig. 4-7 Adder-Subtractor Design: (A+B)OR (A-B) • Output is result if A >= B; Discard carry • Output is 2’s complement of result if B > A**Signed Binary**• Signed magnitude • Left bit is sign, 0 positive, 1 negative • Other bits are number • 2’s complement • 1’s complement**Example in 8-bit byte**• Represent -910 = -(0000 1001) in different ways “Signed magnitude” of - (0000 1001) is 10001001 “Signed 1’s Complement” of - (0000 1001) is 11110110 “Signed 2’s Complement” of - (0000 1001) is 11110111**Observations (assume 4-bit numbers)**• 1’s C and Signed Magnitude have two zeros • 2’s C has more negative numbers than positive • All negative numbers have 1 in highest-order bit**Advantages/Disadvantages**• Signed magnitude & One’s complement has a positive and negative zero • Two’s complement is most popular • Arithmetic operations easy**Two’s Complement**• Addition easy on any combination of positive and negative numbers • To compute A - B • Take 2’s complement of subtrahend B to produce -B • Add to A • This performs A + ( -B), same as A – B**Examples**• Assume we use 2’s complement representation of signed numbers • Store each number in 8 bits 6 = (0000 0110) ; 13 = (0000 1101) -6 = (1111 1010) ; -13 = (1111 0011) • Addition • 6 + 13 • -6 + 13 • 6 + (- 13) • (-6) + (-13) • Subtraction • -6 - (-13) • 6 - (- 13)**Overflow**• Overflow means that result can not be represented with the number of bits used • Two cases of overflow for addition of signed numbers • Two large positive numbers overflow into sign bit • Not enough bits for result • Two large negative numbers added • Same – Not enough bits for result**Examples:Work on Board**Assume 1- We use “2’s complement representation” of signed numbers 2- Store each number in 4 bits : b3 b2 b1 b0**Example 1**• 7 + 7 • Overflow: can not represent 14 using only 4 bits • Generates NO CARRY, C4 = 0**Example 2**• -7 - 7 • Overflow: can not represent -14 using only 4 bits • Generates CARRY, C4 = 1**Example 3**• 4 + 4 • Overflow: can not represent 8 using only 4 bits • Generates NO CARRY, C4 = 0**Example 4**• 7 – 7 • NO Overflow • Generates CARRY, C4 = 1**Fig. 4-8**--------------------------------------------------------- Fig. 5-9 Overflow Detection for Addition and Subtraction Overflow Detection • Condition for overflow: • either Cn-1 or Cn is high, but not both • 7 + 7; only Cn-1 (C3) is high ; overflow • -7 - 7; only Cn (C4)is high ; overflow • 4 + 4; only Cn-1 (C3) is high ; overflow • 7 – 7; BOTH Cn-1 & Cn (C4 & C3) are high; no overflow