1 / 28

Symbol Representation and Floating Point Numbers Chapters 2 and 3

Symbol Representation and Floating Point Numbers Chapters 2 and 3. Vishwani D. Agrawal James J. Danaher Professor Department of Electrical and Computer Engineering Auburn University http://www.eng.auburn.edu/~vagrawal vagrawal@eng.auburn.edu. Symbol Representation.

konala
Télécharger la présentation

Symbol Representation and Floating Point Numbers Chapters 2 and 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Symbol Representation and Floating Point NumbersChapters 2 and 3 Vishwani D. Agrawal James J. Danaher Professor Department of Electrical and Computer Engineering Auburn University http://www.eng.auburn.edu/~vagrawal vagrawal@eng.auburn.edu ELEC 5200-001/6200-001 Lecture 8

  2. Symbol Representation • Early versions (60s and 70s) • Six-bit binary code (CDC) • EBCDIC – extended binary coded decimal interchange code (IBM) • Presently used – • ASCII – American standard code for information interchange – byte (8 bit) code specified by American National Standards Institute (ANSI) • Unicode – 16 bit code and an extended 32 bit version ELEC 5200-001/6200-001 Lecture 8

  3. ASCII • Each byte pattern represents a character (symbol) • Convenient to write in hexadecimal, e.g., • 00000000 0ten 00hex null • 01000001 65ten 41hex A • 01100001 97ten 61hex a • See Figure 2.21, page 91 (Edition 3) or Figure 3.15, page 142 (Edition 2) • C program – string -- terminating with a null byte 01000101 01000011 01000101 00000000 69ten, 45hex 67ten,43hex 69ten, 45hex 00ten, 00hex E C E ELEC 5200-001/6200-001 Lecture 8

  4. MIPS: load byte, store byte • lb $t0, 0($sp) # read byte from memory • sb $t0, 0($gp) # write byte to memory • Examine the string copy procedure (C code) and the corresponding MIPS assembly code on pages 92-93 (pages 143-144 in Edition 2). ELEC 5200-001/6200-001 Lecture 8

  5. Floating Point Numbers • Integers: the universe is infinite but discrete • No fractions • No numbers between 5 and 6 • A countable (finite) number of items in a finite range • Real numbers – the universe is infinite and continuous • Fractions represented by decimal notation • Rational numbers, e.g., 5/2 = 2.5 • Irrational numbers, e.g., 22/7 = 3.14159265 . . . • Infinite numbers exist even in the smallest range ELEC 5200-001/6200-001 Lecture 8

  6. Wide Range of Numbers • A large number: 976,000,000,000,000 = 9.76 × 1014 • A small number: 0.0000000000000976 = 9.76 × 10-14 ELEC 5200-001/6200-001 Lecture 8

  7. Scientific Notation • Decimal numbers • 0.513×105, 5.13×104 and 51.3×103 are written in scientific notation. • 5.13×104 is in normalized scientific notation. • Binary numbers • Base 2 • Binary point – multiplication by 2 moves the point to the left. • Normalized scientific notation, e.g., 1.0two×2-1 • Known as floating point numbers. ELEC 5200-001/6200-001 Lecture 8

  8. Floating Point Numbers • General format ±1.bbbbb two×2eeee or (-1)S × (1+F) × 2E • Where • S = sign, 0 for positive, 1 for negative • F = fraction (or mantissa) as a binary integer, 1+F is called significand • E = exponent as a binary integer, positive or negative (two’s complement) ELEC 5200-001/6200-001 Lecture 8

  9. Binary to Decimal Conversion Binary (-1)S (1.b1b2b3b4) × 2E Decimal (-1)S × (1 + b1×2-1 + b2×2-2 + b3×2-3 + b4×2-4) × 2E Example: -1.1100 × 2-2 (binary) = - (1 + 2-1 + 2-2) ×2-2 = - (1 + 0.5 + 0.25)/4 = - 1.75/4 = - 0.4375 (decimal) ELEC 5200-001/6200-001 Lecture 8

  10. MIPS Single Precision • Max |E| ~ 127, 2127 ~ 1038 • Range of magnitudes, 2×10-38 to 2×1038 • Overflow: Exponent requiring more than 8 bits. Number can be positive or negative. • Underflow: Fraction requiring more than 23 bits. Number can be positive or negative. S E: 8-bit Exponent F: 23-bit Fraction bits 23-30 bits 0-22 bit 31 ELEC 5200-001/6200-001 Lecture 8

  11. MIPS Double Precision • Max |E| ~ 1023, 21023 ~ 10308 • Range of magnitudes, 2×10-308 to 2×10308 • Overflow: Exponent requiring more than 11 bits. Number can be positive or negative. • Underflow: Fraction requiring more than 52 bits. Number can be positive or negative. S E: 11-bit Exponent F: 52-bit Fraction + bits 20-30 bits 0-19 bit 31 Continuation of 52-bit Fraction bits 0-31 ELEC 5200-001/6200-001 Lecture 8

  12. IEEE 754 Floating Point Standard • Biased exponent: true exponent range [-127,127] is changed to [0, 255]: • Biased exponent is an 8-bit positive binary integer. • True exponent obtained by subtracting 127ten or 01111111two • First bit of significand is always 1: ± 1.bbbb . . . b × 2E • 1 before the binary point is implicitly assumed. • Significand field represents 23 bit fraction after the binary point. • Significand range is [1, 2). ELEC 5200-001/6200-001 Lecture 8

  13. Examples Biased exponent (0-255), bias 127 (01111111) to be subtracted 1.1010001 × 210100 = 0 10010011 10100010000000000000000 = 1.6328125 × 220 -1.1010001 × 210100 = 1 10010011 10100010000000000000000 = -1.6328125 × 220 1.1010001 × 2-10100 = 0 01101011 10100010000000000000000 = 1.6328125 × 2-20 -1.1010001 × 2-10100 = 1 01101011 10100010000000000000000 = -1.6328125 × 2-20 0.5 0.125 0.0078125 0.6328125 ELEC 5200-001/6200-001 Lecture 8

  14. Numbers in 32-bit Formats • Two’s complement integers • Floating point numbers • Ref: W. Stallings, Computer Organization and Architecture, Sixth Edition, Upper Saddle River, NJ: Prentice-Hall. Expressible numbers -231 0 231-1 Positive underflow Negative underflow Negative Overflow Expressible negative numbers Expressible positive numbers Positive Overflow -2-127 0 2-127 - (2 – 2-23)×2127 (2 – 2-23)×2127 ELEC 5200-001/6200-001 Lecture 8

  15. Positive Zero in IEEE 754 • + 1.0 × 2-127 • Smallest positive number in single-precision IEEE 754 standard. • Interpreted as positive zero. • Exponentless than -127 is positive underflow; can be regarded as zero. 0 0000000000000000000000000000000 Biased exponent Fraction ELEC 5200-001/6200-001 Lecture 8

  16. Negative Zero in IEEE 754 • - 1.0 × 2-127 • Smallest negative number in single-precision IEEE 754 standard. • Interpreted as negative zero. • True exponent less than -127 is negative underflow; may be regarded as 0. 1 0000000000000000000000000000000 Biased exponent Fraction ELEC 5200-001/6200-001 Lecture 8

  17. Positive Infinity in IEEE 754 • + 1.0 × 2128 • Largest positive number in single-precision IEEE 754 standard. • Interpreted as + ∞ • If true exponent = 128 and fraction ≠ 0, then the number is greater than ∞. It is called “not a number” or NaN and may be interpreted as ∞. 0 1111111100000000000000000000000 Biased exponent Fraction ELEC 5200-001/6200-001 Lecture 8

  18. Negative Infinity in IEEE 754 • -1.0 × 2128 • Smallest negative number in single-precision IEEE 754 standard. • Interpreted as - ∞ • If true exponent = 128 and fraction ≠ 0, then the number is less than - ∞. It is called “not a number” or NaN and may be interpreted as - ∞. 1 1111111100000000000000000000000 Biased exponent Fraction ELEC 5200-001/6200-001 Lecture 8

  19. Addition and Subtraction 0. Zero check - Change the sign of subtrahend - If either operand is 0, the other is the result 1. Significand alignment: right shift smaller significand until two exponents are identical. 2. Addition: add significands and report exception if overflow occurs. 3. Normalization - Shift significand bits to normalize. - report overflow or underflow if exponent goes out of range. 4. Rounding ELEC 5200-001/6200-001 Lecture 8

  20. Example • Subtraction: 0.5ten- 0.4375ten • Step 0: Floating point numbers to be added 1.000two×2-1 and -1.110two×2-2 • Step 1: Significand of lesser exponent is shifted right until exponents match -1.110two×2-2 →- 0.111two×2-1 • Step 2: Add significands, 1.000two + (- 0.111two) Result is 0.001two×2-1 ELEC 5200-001/6200-001 Lecture 8

  21. Example (Continued) • Step 3: Normalize, 1.000two× 2-4 No overflow/underflow since 127 ≥ exponent ≥ -126 • Step 4: Rounding, no change since the sum fits in 4 bits. 1.000two×2-4 = (1+0)/16 = 0.0625ten ELEC 5200-001/6200-001 Lecture 8

  22. FP Multiplication: Basic Idea • Separate sign • Add exponents • Multiply significands • Normalize, round, check overflow • Replace sign ELEC 5200-001/6200-001 Lecture 8

  23. FP Multiplication: Step 0 Multiply, X × Y X = 0? Y = 0? yes no Steps 1 - 5 no yes Z = 0 Return ELEC 5200-001/6200-001 Lecture 8

  24. FP Mult. Illustration • Multiply 0.5ten and -0.4375ten(answer = - 0.21875ten) or • Multiply 1.000two×2-1 and -1.110two×2-2 • Step 1: Add exponents -1 + (-2) = -3 • Step 2: Multiply significands 1.000 ×1.110 0000 1000 1000 1000 1110000 Product is 1.110000 ELEC 5200-001/6200-001 Lecture 8

  25. FP Mult. Illustration (Cont.) • Step 3: • Normalization: If necessary, shift significand right and increment exponent. Normalized product is 1.110000 × 2-3 • Check overflow/underflow: 127 ≥ exponent ≥ -126 • Step 4: Rounding: 1.110 × 2-3 • Step 5: Sign: Operands have opposite signs, Product is -1.110 × 2-3 Decimal value = - (1+0.5+0.25)/8 = - 0.21875ten ELEC 5200-001/6200-001 Lecture 8

  26. FP Division: Basic Idea • Separate sign. • Check for zeros and infinity. • Subtract exponents. • Divide significands. • Normalize/overflow/underflow. • Rounding. • Replace sign. ELEC 5200-001/6200-001 Lecture 8

  27. MIPS Floating Point • 32 floating point registers, $f0, . . . , $f31 • FP registers used in pairs for double precision; $f0 denotes double precision content of $f0,$f1 • Data transfer instructions: • lwc1 $f1, 100($s2) # $f1←Mem[$s1+100] • swc1 $f1, 100($s2) # Mem[$s2+100]←$f1 • Arithmetic instructions: (xxx=add, sub, mul, div) • xxx.s single precision • xxx.d double precision ELEC 5200-001/6200-001 Lecture 8

  28. Recommended (Not Mandatory) • Visit www.computerhistory.org to learn about the developments in computers. Many of the names and events in your book and those discussed in the class appear there. • When in Silicon Valley, visit the Computer History Museum (Route 101, Mountain View, CA). ELEC 5200-001/6200-001 Lecture 8

More Related