digital design
play

Digital Design Discussion: Arithmetic Binary Arithmetic - PowerPoint PPT Presentation

Principles Of Digital Design Discussion: Arithmetic Binary Arithmetic Floating-Point Arithmetic Binary Arithmetic Same basic methodology as decimal arithmetic Important to know number representation Unsigned Signed


  1. Principles Of Digital Design Discussion: Arithmetic Binary Arithmetic Floating-Point Arithmetic

  2. Binary Arithmetic  Same basic methodology as decimal arithmetic  Important to know number representation  Unsigned  Signed (signed-magnitude)  Two’s complement  Binary values converted to decimal: Binary Number Unsigned Value Signed Value Two's Complement Value 101101 45 -13 -19 011101 29 29 29 DIGITAL DESIGN 101, University of California Arithmetic

  3. Binary Arithmetic: Unsigned  Addition of unsigned binary numbers: x i y i c i c i +1 s i 0 0 0 0 0  Valid range (6 bits): 0 – 63 0 0 1 0 1  Overflow for addition: 0 1 0 0 1 0 1 1 1 0  Number too large 1 0 0 0 1  Notify when overflow occurs 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 Addition of Binary Digits 32 16 8 4 2 1 x (45) 1 0 1 1 0 1 + y + (29) 0 1 1 1 0 1 Carries 1 1 1 1 0 1 x + y (74) 1 0 0 1 0 1 0 s 6 s 5 s 4 s 3 s 2 s 1 s 0 Signed Binary Addition DIGITAL DESIGN 101, University of California Arithmetic

  4. Binary Arithmetic: Unsigned  Subtraction of unsigned binary numbers: x i y i b i b i+1 d i 0 0 0 0 0  Valid range (6 bits): 0 – 63 0 0 1 1 1  Overflow for subtraction: 0 1 0 1 1 0 1 1 1 0  Number too small 1 0 0 0 1  Notify when overflow occurs 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 Subtraction of Binary Digits 32 16 8 4 2 1 x (29) 0 1 1 1 0 1 - y - (45) 1 0 1 1 0 1 Borrows 1 0 0 0 0 0 x + y (48) 1 1 1 0 0 0 0 s 6 s 5 s 4 s 3 s 2 s 1 s 0 Signed Binary Addition DIGITAL DESIGN 101, University of California Arithmetic

  5. Binary Arithmetic: Signed-Magnitude  Addition of signed-magnitude binary numbers: x i y i b i b i+1 d i 0 0 0 0 0  Valid range (6 bits): -31 – 31 0 0 1 1 1  Numbers are both positive: 0 1 0 1 1 0 1 1 1 0  Sign change = overflow 1 0 0 0 1  Numbers are both negative: 1 0 1 0 0 1 1 0 0 0  Result is “+” & overflow: flip sign (result ok) 1 1 1 1 1  Result is “-” & overflow: overflow Subtraction of Binary Digits  Numbers have different signs: +/- 16 8 4 2 1  No overflow x (29) 0 1 1 1 0 1  Methodology +y - (13) 0 0 1 1 0 1  Larger number on top ( x ) Borrows 0 0 0 0 0  Change sign of y and subtract x + y (16) 0 1 0 0 0 0 s 5 s 4 s 3 s 2 s 1 s 0 Sign-Magnitude Binary Addition with Different Signs DIGITAL DESIGN 101, University of California Arithmetic

  6. Binary Arithmetic: Signed-Magnitude  Subtraction of signed-magnitude numbers: x i y i c i c i +1 s i 0 0 0 0 0  Valid range (6 bits): -31 – 31 0 0 1 0 1  Numbers have different signs: 0 1 0 0 1 0 1 1 1 0  Change sign of “-” and add 1 0 0 0 1  Overflow cases same as addition 1 0 1 1 0 1 1 0 1 0  Numbers are both positive: 1 1 1 1 1  Subtract normally Addition of Binary Digits  No overflow +/- 16 8 4 2 1  Numbers are both negative: x (29) 0 1 1 1 0 1  Change sign of y and add - y + (13) 0 0 1 1 0 1  No overflow Carries 1 1 1 0 1  Need to keep track of proper sign x – y (-10) 1 0 1 0 1 0 s 5 s 4 s 3 s 2 s 1 s 0 Sign-Magnitude Binary Subtraction with Different Signs DIGITAL DESIGN 101, University of California Arithmetic

  7. Binary Arithmetic: Two’s Complement  Addition of two’s complement numbers: x i y i c i c i +1 s i 0 0 0 0 0  Valid range (6 bits): -32 – 31 0 0 1 0 1  Numbers have different signs: 0 1 0 0 1 0 1 1 1 0  Can ignore carry (no overflow) 1 0 0 0 1 1 0 1 1 0  Numbers have same signs: 1 1 0 1 0  Sign change = overflow 1 1 1 1 1  Methodology: Addition of Binary Digits  Same as standard binary addition +/- 16 8 4 2 1 x (-19) 1 0 1 1 0 1 y + (29) 0 1 1 1 0 1 Carries 1 1 1 1 0 1 x + y (10) 0 0 1 0 1 0 s 5 s 4 s 3 s 2 s 1 s 0 Two’s Complement Addition DIGITAL DESIGN 101, University of California Arithmetic

  8. Binary Arithmetic: Two’s Complement  Subtraction of two’s complement numbers: x i y i c i c i +1 s i 0 0 0 0 0  Valid range (6 bits): -32 – 31 0 0 1 0 1  Same overflow cases as two’s complement addition 0 1 0 0 1 0 1 1 1 0  Methodology: 1 0 0 0 1 1 0 1 1 0  Perform two’s complement on y and add 1 1 0 1 0 1 1 1 1 1 Addition of Binary Digits +/- 16 8 4 2 1 x (-19) 1 0 1 1 0 1 - y + (-29) 1 0 0 0 1 1 Carries 1 0 1 1 1 1 x + y (16) 0 1 0 0 0 0 s 5 s 4 s 3 s 2 s 1 s 0 Two’s Complement Subtraction (Complementing y and Add) DIGITAL DESIGN 101, University of California Arithmetic

  9. Shift-and-add Multiplication  Example of shift-and-add multiplication with unsigned binary numbers 1 1 1 1 0 multiplicand (30) × 1 0 1 multiplier (5) 0 0 0 0 0 initial partial product 1 * multiplicand, no shift 1 1 1 1 0 second partial product 1 1 1 1 0 0 * multiplicand, shift 0 0 0 0 0 third partial product 0 1 1 1 1 0 1 * multiplicand, shift 1 1 1 1 0 (carries) 1 1 1 1 product (150) 1 0 0 1 0 1 1 0 9 DIGITAL DESIGN 101, University of California Arithmetic

  10. Two’s-complement Multiplication  Use multiplication procedure for unsigned numbers  Extend partial products  Negate multiplicand in last step if multiplier sign is negative 1 0 1 0 multiplicand (–6) × 0 0 1 1 multiplier (3) Note: 0 0 0 0 0 extended partial product • Red = ignored carry 1 1 0 1 0 1 * multiplicand, extend, no shift extended partial product 1 1 1 0 1 0 1 * multiplicand, extend, shift 1 1 0 1 0 (carries) 1 1 extended partial product 1 1 0 1 1 1 0 0 * multiplicand, extend, shift 0 0 0 0 0 1 1 1 0 1 1 1 0 extended partial product 0 * multiplicand, extend, shift 0 0 0 0 0 product ( – 18) 1 1 1 0 1 1 1 0 10 DIGITAL DESIGN 101, University of California Arithmetic

  11. Floating-Pointing Addition  Problem: Add 1.110 2 x 2 3 and 1.011 2 x 2 4  Procedure: 1. Make two numbers have same exponents (shift mantissa)  Right shift 1.110 by 1 bit (divide by 2) to become 0.111  So 1.110 x 2 3 = 0.111 x 2 4 2. Add mantissas 0 1 1 1 1 0 1 1 Carries 1 1 1 1 1 0 0 1 0 Implied binary point  0.111 + 1.011 = 10.010 3. Normalize (shift mantissa)  Result: 10.010 x 2 4 = 1.001 x 2 5 DIGITAL DESIGN 101, University of California Arithmetic

Recommend


More recommend