Presentation is loading. Please wait.

Presentation is loading. Please wait.

CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.

Similar presentations


Presentation on theme: "CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics."— Presentation transcript:

1 CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics Arizona State University Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB

2 CML CMLAnnouncements Quiz 2 Project 2 Quiz 3 –Thursday, Oct 06, 2009 –Complete Chapter 3 Project 3 –Implement an assembler

3 CML CML Floating Point (Real) Numbers We need a way to represent –numbers with fractions, e.g., 3.1416 –very small numbers, e.g.,.000000001 –very large numbers, e.g., 3.15576  10 9 Representation: –sign, exponent, significand: (–1)sign  significand  2 exponent –more bits for significand gives more accuracy –more bits for exponent increases range IEEE 754 floating point standard: –single precision: 8 bit exponent, 23 bit significand

4 CML CML S IEEE 754 floating-point standard IEEE Floating Point: (-1) S  1.M  2 E-127 –Mantissa (sign and magnitude -- S, M) –Exponent (excess 127 binary number -- E) EM 1 bit 8 bits 23 bits Example: –decimal: -.75 = - ( ½ + ¼ ) –binary: -.11 = -1.1 x 2 -1 –floating point: exponent = 126 = 01111110 –IEEE single precision: 1 01111110 10000000000000000000000

5 CML CMLRemember For FP Number –Value = (-1) S *1.M*2 E-127 1 st bit is the sign bit Exponent = E-127 –Why? Mantissa is after the decimal –1.1100111  Mantissa is 1100111

6 CML CML IEEE FP Numbers Example: 0 1000 0011 1101 0000 0000 0000 0000 000 – S = 0 (positive mantissa), E = 131 - 127 = 4, and M =.1101 –the number = 1.1101 x 2 4 = 11101 = 29 Example: 1 0111 1011 1101 0000 0000 0000 0000 000 – S = 1 (negative mantissa), E = 123 - 127 = -4, and M =.1101 –the number = -1.1101 x 2 -4 = -0.00011101 = -(2 -4 + 2 -5 + 2 -6 + 2 -8 ) = -0.11328125 Example: -10.609375 10.609375 = (1010.100111) 2 = 1.010100111 x 2 3 –S = 1, E = 3+127 = 130 = 1000 0010, and M = 010100111... –FP: 1 1000 0010 0101 0011 1000 0000 0000 000 0.609375 x 2 1.21875 x 2 0.4375 x 2 0.875 x 2 1.75 x 2 1.5 x 2 1.0

7 CML CML FP Addition Compute 9.999*10 1 + 1.610*10 -1, assuming only 3 places in decimal 1.Make the exponents same 9.999*10 1 + 0.01610*10 1 2.Add the significands 10.015*10 1 3.Normalize 1.0015*10 2 4.Round-off 1.002*10 2

8 CML CML FP Addition Example 1.1101 x 2 3 + 1.001 x 2 -1 = 1.1101 x 2 3 + 0.0001001x2 3 =1.1110001 x 2 3 Steps: X(m,e) + Y(m,e) –Shift the smaller operand --- align binary point compute Ye-Xe, right shift Xm  Xm’ if Ye > Xe –Add magnitudes (Xm’ + Ym) –Normalize and round-off if necessary

9 CML CML FP Subtraction 0.5 10 – 0.4375 10 Step 1: Convert into FP Representation –0.5 10 = 1.000 x 2 -1 –-0.4375 10 = -1.110x2 -2 Step 2: Shift significand of smaller number –-1.110x2 -2 = -0.111x2 -1 Step 3: Subtract the significands –1.000 x 2 -1 - 0.111x2 -1 = 0.001x2 -1 Step 4: Normalize the sum, check for over/underflow –= 0.001x2 -1 = 1.000x2 -4 Step 5: Round off –1.000x2 -4 Step 6: Result –1.000x2 -4 = 0.0625

10 CML CML FP Multiply Compute 1.110*10 10 *9.200*10 -5 assuming digit significands 1.Add the exponents Exponent = 10-5 = 5 2.Multiply the significands 1.110*9.200 = 10.212000 3.Normalize 1.0212000*10 6 4.Round-off 1.021*10 6

11 CML CML FP Multiply Assume 4-bit mantissa compute 0 0111 1110 0101 x 0 0111 1101 1110 –add exponent and adjust the bias: 0111 1110 + 0111 1101 - 0111 1111 = 0111 1100 –multiply 1.0101 and 1.1110  10.0111 0110 –normalize and detect underflow or overflow: exponent: 0111 1101, mantissa: 1.0011 1011 0 –round the product and the result is 0 0111 1101 0100 compute (1.0101 x 2 -1 ) x (1.1110 x 2 -2 ) =.65625 x.46875 =0.3076171875 = 10.01110110 x 2 -3 = 1.001110110 x 2 -2 =.3076171875 = 0 0111 1101 0100 =.3125

12 CML CML IEEE 754 Floating Point Numbers Special Representation –When exponent is 1111 1111 or 0000 0000 TypeExponentFraction Zeroes00 De-normalized numbers 0non zero Normalized numbers 1 to 2 e − 2any Infinities2 e − 10 NaNs2 e − 1non zero

13 CML CML IEEE 754 FP Representation There are two Zeroes –+0 (s is 0) and −0 (s is 1) There are two Infinities –+∞ (s is 0) and −∞ (s is 1) Numbers closest to zero –is a denormalized value –all 0s in the Exp field and the binary value 1 in the Fraction field –±2 −149 ≈ ±1.4012985×10 −45 Normalized numbers closest to zero –binary value 1 in the Exp field and 0 in the fraction field) –±2 −126 ≈ ±1.175494351×10 −38 Finite numbers furthest from zero –254 in the Exp field and all 1s in the fraction field –±(1-2 -24 )×2 128[2] ≈ ±3.4028235×10 38

14 CML CML Inaccuracy in FPs ExponentMinimumMaximumPrecision 011.9999998807911.19209289551e-7 123.999999761582.38418579102e-7 247.999999523164.76837158203e-7 1010242047.999877931.220703125e-4 1120484095.999755862.44140625e-4 238388608167772151 2416777216335544302 1271.7014e383.4028e382.02824096037e31 Double precision arithmetic Double word – 64-bits 11 bit exponent, 52 bit mantissa

15 CML CML FP numbers Limited precision: (- 1.5 x 10 38 + 1.5 x 10 38 ) + 1 = 0 + 1 = 1 -1.5 x 10 38 + (1.5 x 10 38 + 1) = -1.5 x 10 38 + 1.5 x 10 38 = 0 A view of FP representation, (assume 4 bit precision) There is a big gap between two large consecutive numbers: –gap = 2 -23 x 2 e-127 Add de-normal numbers (exponent=0, mantissa >0) to fill the gap between 0 and 2 -126 02 -126 2 -124 2 -125 de-normal numbers

16 CML CML The Patriot Missile Failure On February 25, 1991, during the Gulf War, an American Patriot Missile battery in Dharan, Saudi Arabia, failed to track and intercept an incoming Iraqi Scud missile. The Scud struck an American Army barracks, killing 28 soldiers and injuring around 100 other people http://www.ima.umn.edu/~arnold/disasters/patriot.html

17 CML CML The Patriot Missile Failure - I Computed time on 1/10 th of seconds In 24-bit precision arithmetic Truncation instead of round-off –1/10 = 0.0001100110011001100110011001100 Patriot Stored – 0.00011001100110011001100 Error – 0.0000000000000000000000011001100 –= 0.000000095 decimal

18 CML CML The Patriot Missile Failure Patrioit battery was up for more than 100 hours Accumulated Error: –0.000000095×100×60×60×10=0.34 1/10 ths of a second Speed of scud is 1,676 meters per second, and so travels more than half a kilometer in this time Completely out of range

19 CML CML Explosion of the Ariane 5 On June 4, 1996 an unmanned Ariane 5 rocket launched by the European Space Agency exploded just forty seconds after its lift- off from Kourou, French Guiana. The rocket was on its first voyage, after a decade of development costing $7 billion. The destroyed rocket and its cargo were valued at $500 million. A board of inquiry investigated the causes of the explosion and in two weeks issued a report. It turned out that the cause of the failure was a software error in the inertial reference system. Specifically a 64 bit floating point number relating to the horizontal velocity of the rocket with respect to the platform was converted to a 16 bit signed integer. The number was larger than 32,767, the largest integer storeable in a 16 bit signed integer, and thus the conversion failed.

20 CML The Number Agenda Unsigned Numbers –Representation, –Addition, Subtraction –Multiplication, Division Signed Numbers –Representation –Addition, Subtraction –Multiplication, Division Floating Point Numbers (For large and fractions) –Representation –Addition, Subtraction –Multiplication (d 31 d 30 … d 2 d 1 d 0 ) 2 = d 31 *2 31 + d 30 *2 30 + … d 2 *2 2 + d 1 * 2 1 + d 0 *2 0 (d 31 d 30 … d 2 d 1 d 0 ) 2 = (-1)*2 31 + d 30 *2 30 + … d 2 *2 2 + d 1 * 2 1 + d 0 *2 0 (d 31 d 30 … d 2 d 1 d 0 ) 2 = (-1)*d 31 * 1.d 22 … d 0 * 2 (d 30 …d 23 - 127)

21 CML CML Yoda says… Luke: I can’t believe it. Yoda: That is why you fail


Download ppt "CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics."

Similar presentations


Ads by Google