Presentation is loading. Please wait.

Presentation is loading. Please wait.

M68K Assembly Language Programming Bob Britton Chapter 12 IEEE Floating Point Notice: Chapter slides in this series originally provided by B.Britton. This.

Similar presentations


Presentation on theme: "M68K Assembly Language Programming Bob Britton Chapter 12 IEEE Floating Point Notice: Chapter slides in this series originally provided by B.Britton. This."— Presentation transcript:

1 M68K Assembly Language Programming Bob Britton Chapter 12 IEEE Floating Point Notice: Chapter slides in this series originally provided by B.Britton. This version of chapter 12 slides have been modified by R.Renner to reflect Spring 2006 course content.

2 Typically floating-point numbers are used in scientific and engineering calculations. For example the velocity of light is 186,281.7 miles per second. A light year, the distance traveled by light in one year is 5,880,000,000,000 miles. The atomic weight of hydrogen is 1.008. A micron, which is one millionth of a meter, is 0.000 000 039 37 inches. Below, each of these numbers is represented in normalized scientific notation. 0.1862817 x 10 +6 0.588 x 10 +13 0.1008 x 10 +1 0.3937 x 10 -7

3 There is a 32-bit (single precision), and a 64-bit (double precision) IEEE standard. In the single precision format, 7 decimal digits of precision can be encoded, and the exponent scale factor has a range of approximately 10 +-38. In the double precision format, 16 decimal digits of precision can be encoded, and the exponent scale factor has a range of approximately 10 +-308.

4 Binary Floating-Point to Decimal Floating-Point Conversion In general, a floating-point number has an integer part and a fractional part. For example given the floating point decimal number 295.48, two hundred ninety-five is the integer part and 0.48 is the fractional part. Any decimal floating-point number has a polynomial expansion. For example the polynomial expansion for the decimal value 295.48 is: 2 * 10 2 + 9 * 10 1 + 5 * 10 0 + 4 * 10 -1 + 8 * 10 -2

5 By the same token, a binary floating-point binary number has a polynomial expansion. For example the polynomial expansion for the binary floating-point value 101.101 is: 1 * 2 2 + 0 * 2 1 + 1 * 2 0 + 1 *2 -1 + 0 * 2 -2 + 1 * 2 -3 Finding the decimal equivalent of any floating-point binary number simply involves evaluating the polynomial expansion. You will find the following table for the powers of two extremely useful when performing this conversion process. 2 4 2 3 2 2 2 1 2 0 2 -1 2 -2 2 -3 2 -4 2 -5 2 -6 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125 0.015625 Using this table we evaluate the polynomial for the binary number 101.101 as: 1*4 + 0*2 + 1*1 + 1*0.5 + 0*0.25 + 1*0.125 = 5.625

6 Decimal Floating-Point to Binary Floating-Point Conversion Suppose we want to find the binary floating-point equivalent of the decimal number 25.25. To convert a decimal integer to binary we repeatedly dividing by 2 and record the remainder after each division. For example the decimal value 25 is equivalent to 11001 in binary. Suppose we want to find the binary floating-point equivalent of the decimal number 25.25. The process of finding the binary equivalent of the decimal fraction portion involves repeatedly multiplying the decimal fraction by two and recording the integer value portion of one (1) or zero (0) that is produced.

7 Given this procedure let’s find the binary equivalent of the decimal value 0.25. 0. 2 5 First Digit after binary point0. 5 Second Digit after binary point1. 0 Done So we now can say that the decimal value 25.25 is represented in binary as: 11001.01

8 As a second example we will convert the decimal vale 12.2 to binary. We should have no difficulty in finding that the decimal value 12 is represented in binary as 1100. We now need to find the binary equivalent of the decimal fraction 0.2 0. 2 First digit after binary point0. 4 Second digit after binary point0. 8 Third digit after binary point1. 6 Forth digit after binary point1. 2 The above sequence repeats forever So we now can say that the decimal value 12.2 cannot be represent exactly in binary, but a close approximation is: 1100.00110011001100110011001100110011001100110011

9 The IEEE 754 Floating-Point Standard The IEEE 754 single precision floating-point format is illustrated below: 8-bit 23-bit Sign Biased exponentSignificand The IEEE 754 single precision floating-point format specifies three distinct fields: The sign of the number (0: positive, 1: negative) The biased exponent (The actual exponent value plus 127) A value for the significand, which is the magnitude of the binary fractional portion

10 Procedure to encode a binary floating-point value in the IEEE format You recall that 11001.01 is the binary equivalent of 25.25 in the decimal number system. (A correction to the book is shown here) Enter a value for the sign bit (0: positive, 1: negative) Normalize the binary representation so that the binary point is to the right of the first one (1). 25.25 = 11001.01 = 1.100101 x 2 4 10 22 Add 127 (01111111) to the actual exponent and place this value into the 8-bit biased exponent field. For this example we would get: 127 + 4 = 131 = (10000011) 10 2 Fill in the 23-bit significand field with all the digits to the right of the binary point that appear in the normalized representation. Since all normalized numbers (except zero) have a leading one (1) this bit does not occupy a position within the encoding. This implicit bit is called the “hidden-bit.” 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

11 Special Encodings Any non zero value111111110/1 Not a Number 00000000000000000000000111111110/1Infinity Any non zero value000000000/1Denomalized 00000000000000000000000000000000/1Zero SignificandExponent sign Interpretation

12 Decoding Numbers the IEEE 754 Floating-Point Standard A specific example will be provided to demonstrate the rules. Suppose we are given the following IEEE single precision binary floating-point representation for a number, and we want to determine the equivalent value as a floating-point decimal number. 1 1 0 0 0 0 1 0 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 The first bit indicates the sign of the number (0: positive, 1: negative). For this example, we have a negative decimal number encoded. Subtract 127 from the value found in the biased exponent field to determine the actual exponent. For this example the actual exponent is 6. (133 - 127 = 6) Using the significand bits write the number in normalized binary representation. Remember to include the recreated hidden-bit and an indication of the sign of the number. For this example, we have -1.0011011 x 2 6 Denormalize the number by moving the binary point the number of positions indicated by the actual exponent. For our example, the de-normalized number is: -1001101.1 In the final step we simply perform a binary to decimal conversion by evaluating the polynomial expansion of the binary number. For this example we determine that -77.5 is the equivalent decimal value.

13 IEEE 757 Floating Point Representation Practice Conversions 15.25 ten = 1111.01 two =>> 1.11101 x 2 3 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 What is the decimal equivalent of the following number given in IEEE 757 floating point notation? 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

14 One More Exercise 10.5 ten = 1010.1 two =>> 1.0101 x 2 3 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


Download ppt "M68K Assembly Language Programming Bob Britton Chapter 12 IEEE Floating Point Notice: Chapter slides in this series originally provided by B.Britton. This."

Similar presentations


Ads by Google