Topics Integer Arithmetic Floating Point Representation Floating Point

  • Slides: 31
Download presentation
Topics • Integer Arithmetic • Floating Point Representation • Floating Point Arithmetic

Topics • Integer Arithmetic • Floating Point Representation • Floating Point Arithmetic

2’s Complement Integers

2’s Complement Integers

2’s Complement Addition/Subtraction A+B A What is Overflow? How is it identified?

2’s Complement Addition/Subtraction A+B A What is Overflow? How is it identified?

Unsigned Integer Multiplication

Unsigned Integer Multiplication

Unsigned Integer Multiplication Q x M AQ

Unsigned Integer Multiplication Q x M AQ

Unsigned Integer Multiplication Flow Diagram

Unsigned Integer Multiplication Flow Diagram

2’s Comp Multiplication Booth’s Algorithm Add one extra bit to the Q register: Q-1

2’s Comp Multiplication Booth’s Algorithm Add one extra bit to the Q register: Q-1

2’s Comp Multiplication Booth’s Algorithm Q-1

2’s Comp Multiplication Booth’s Algorithm Q-1

2’s Comp Multiplication Booth’s Algorithm

2’s Comp Multiplication Booth’s Algorithm

Booth : (7) x (3) A Q M 3 7 0000 0011 0 0111

Booth : (7) x (3) A Q M 3 7 0000 0011 0 0111 ----------1001 0011 0 0111 1100 1001 1 0111 ---------- A <- (A - M) Shift 1 st 2 nd 1110 0100 1 0111 ----------0101 0100 1 0111 0010 1010 0 0111 ---------- Shift A <- (A + M) Shift 3 rd 4 th 0001 0101 0 0111 ---------- Shift

Booth : (7) x (-3) A Q M -3 7 0000 1101 0 0111

Booth : (7) x (-3) A Q M -3 7 0000 1101 0 0111 ----------1001 1101 0 0111 1100 1110 1 0111 ----------0011 1110 1 0111 0001 1111 0 0111 ----------1010 1111 0 0111 1101 0111 ---------- A <- (A - M) Shift 1 st A <- (A + M) Shift 2 nd A <- (A - M) Shift 3 rd 4 th 1110 1011 1 0111 ---------- Shift

Booth : (-7) x (3) A Q M 3 -7 0000 0011 0 1001

Booth : (-7) x (3) A Q M 3 -7 0000 0011 0 1001 ----------0111 0011 0 1001 0011 1001 ---------- A <- (A - M) Shift 1 st 2 nd 0001 1100 1 1001 ----------1010 1100 1 1001 1101 0110 0 1001 ---------- Shift 1110 1011 0 1001 ---------- Shift A <- (A + M) Shift 3 rd 4 th

Booth : (-7) x (-3) A Q M -3 -7 0000 1101 0 1001

Booth : (-7) x (-3) A Q M -3 -7 0000 1101 0 1001 ----------0111 1101 0 1001 0011 1110 1 1001 ----------1100 1110 1 1001 1110 0111 0 1001 ----------0101 0111 0 1001 0010 1011 1 1001 ---------- A <- (A - M) Shift 1 st A <- (A + M) Shift 2 nd A <- (A - M) Shift 3 rd 4 th 0001 0101 1 1001 ---------- Shift

Unsigned Integer Division

Unsigned Integer Division

Unsigned Integer Division

Unsigned Integer Division

Unsigned Integer Division

Unsigned Integer Division

Unsigned Integer Division Divisor M Dividend Q Quotient in Q Remainder in A

Unsigned Integer Division Divisor M Dividend Q Quotient in Q Remainder in A

What about 2’s Comp Division ? • Can we do something like Booth’s Algorithm?

What about 2’s Comp Division ? • Can we do something like Booth’s Algorithm? • Why might we use Booth’s Algorithm for multiplication but not for Division?

Single Precision Floating Point Numbers IEEE Standard 32 bit Single Precision Floating Point Numbers

Single Precision Floating Point Numbers IEEE Standard 32 bit Single Precision Floating Point Numbers are stored as: S EEEE FFFFFFFFFFFF S: Sign – 1 bit E: Exponent – 8 bits F: Fraction – 23 bits Significand The value V: • If E=255 and F is nonzero, then V= Na. N ("Not a Number") • If E=255 and F is zero and S is 1, then V= - Infinity • If E=255 and F is zero and S is 0, then V= Infinity • If 0<E<255 then V= (-1)**S * 2 ** (E-127) * (1. F) (exponent range = -127 to +128) • If E=0 and F is nonzero, then V= (-1)**S * 2 ** (-126) * (0. F) ("unnormalized" values”) • If E=0 and F is zero and S is 1, then V= - 0 • If E=0 and F is zero and S is 0, then V = 0 Note: 255 decimal = 1111 in binary (8 bits)

FP Examples

FP Examples

Double Precision Floating Point Numbers IEEE Standard 64 bit Double Precision Floating Point Numbers

Double Precision Floating Point Numbers IEEE Standard 64 bit Double Precision Floating Point Numbers are stored as: S EEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFF S: Sign – 1 bit E: Exponent – 11 bits F: Fraction – 52 bits Significand The value V: • If E=2047 and F is nonzero, then V= Na. N ("Not a Number") • If E=2047 and F is zero and S is 1, then V= - Infinity • If E=2047 and F is zero and S is 0, then V= Infinity • If 0<E<2047 then V= (-1)**S * 2 ** (E-1023) * (1. F) (exponent range = -1023 to +1024) • If E=0 and F is nonzero, then V= (-1)**S * 2 ** (-1022) * (0. F) ("unnormalized" values) • If E=0 and F is zero and S is 1, then V= - 0 • If E=0 and F is zero and S is 0, then V= 0 Note: 2047 decimal = 111111 in binary (11 bits)

32 bit 2’s Complement Integer Numbers All the Integers from -2, 147, 483, 648

32 bit 2’s Complement Integer Numbers All the Integers from -2, 147, 483, 648 to + 2, 147, 483, 647, i. e. - 2 Gig to + 2 Gig-1

32 bit FP Numbers

32 bit FP Numbers

“Density” of 32 bit FP Numbers Note: ONLY 232 FP numbers are representable There

“Density” of 32 bit FP Numbers Note: ONLY 232 FP numbers are representable There are only 232 distinct combinations of bits in 32 bits !

The Added Denormalized FP Numbers

The Added Denormalized FP Numbers

Floating Point Addition / Subtraction Steps: • Check for zero • Align the significands

Floating Point Addition / Subtraction Steps: • Check for zero • Align the significands (fractions) • Add or Subtract the significands • Normalize the Result Bad Results: • • Exponent Overflow Exponent Underflow Significand Overflow Significand Underflow

Floating Point Addition/Subraction

Floating Point Addition/Subraction

Floating Point Multiplication 1) Check for zero 2) Multiply significands 3) Add exponents 4)

Floating Point Multiplication 1) Check for zero 2) Multiply significands 3) Add exponents 4) Normalize Overflow/underflow?

Floating Point Multiplication

Floating Point Multiplication

Floating Point Division 1) Check for zero 2) Divide significands 3) Subract exponents 4)

Floating Point Division 1) Check for zero 2) Divide significands 3) Subract exponents 4) Normalize Overflow/underflow?

Floating Point Division

Floating Point Division