UMBC CMSC 313

 


FPU Data Representation

So far, everything has involved some form of integers. Now we will address real numbers (floating point numbers). There is a special unit called the Floating Point Unit, or FPU. On some members of the Intel family, the FPU is physically separate known as the numeric coprocessor.

The reality of things is that very few people do any real work in assembly language with floating point numbers. There is not a lot of material that explains it either.

The floating point numbers can be in one of five separate forms:

Floating Point Formats
type C equivalent size (in bits)
short floating point float 32
long floating point double 64
integer (DW) short int 16
long integer (DD) long int 32
Binary Coded Decimal (BCD) NONE 4
*extended floating point NONE 80

* Internal format only

Floating Point Numbers

Since we talked about powers before, we can use that to help us here. If the integer number 100 is 1 X 102, then the number 123 is 1.23 X 102. This is referred to as scientific notation. It lets us represent very large or very small numbers without worrying about a lot of digits in the number. We can also write 1.23 X 102 as 1.23E2. Internally, this is sort of how it is done, but in binary form of course. To make it more complex, we can represent the number -0.00123. This is -1.23X 10-3, or -1.23E-3.

There are three components in the long floating point:

The exponent is biased. That is value is in the range of -1023 to 1024. The bias is 1023, when added to the exponent results in a positive number. (If the exponent is 3, then 1026 is stored as the exponent portion of the floating point number.)

The mantissa the the part of the number that hold the value we are talking about, except that it is normalized. In scientific notation, all numbers are multiplied or divided by ten so that there is only one digit in front of the decimal sign. The exponent is adjusted to compensate for that. 1.23 X 102 is the equivalent of 1.23 X 100. (102 is 100). 1.23 X 100 is 123 when you multiple it out.

In the binary system, we change the power of ten to the power of two. This means that the value when we have a non-zero digit in front of decimal point, it must be a one. Therefore we don't need it, we can assume that it is present!

This means the number is represented as:

( ( -1 )s X 1.b51b50b49...b2b1b0 X 2(exp-1023) b51 = 0.5 if on,
b50 = 0.25 if on,
b49 = 0.125 if on,
etc.
With that we can reconstruct the value to what it is suppose to be when we want to print things out! In C, it would be: printf("%f", myFloat);

Range of Floating Point Numbers

Binary digits and exponents do not correspond exactly to decimal digits and exponent, but the following are the approximate ranges of floating point numbers in decimal:
  decimal digits of precision range of exponent
short 7 10-38 to 1038
long 15 10-308 to 10308
extended 19 10-4932 to 104932

There are two terms that we must understand here, precision and accuracy Precision is the number of digits represented starting with the first non-zero number. 123, -123, 123000, 0.123, and -0.000123 all have a precision of 3. Accuracy is the total number of digits in the value you are trying to represent correctly. 3.140000 could be a seven digit precision but only 3 place accuracy.

Declaring Floating Point Variables

Short floating point variable are declared using the DD directive..
A4   DD   -1.23            ; A negative short fp number
B4   DD   54E23            ; A positive short fp number
C4   DD   -5432            ; A negative long integer
D4   RESD 1                ; A variable which can hold either 
                           ;    a short fp or long integer
E8   DQ   -1.23            ; A negative long fp number
  

Integers

The FPU uses the usual 2's complement integers defined by DW or DD. When declaring data, the way to distinguish between integers and floating point numbers for DD is that the floating point numbers must contain a decimal point (A4 DD -1.23) or they must can an E-part (B4 DD 54E23).

BCD Numbers

BCD (Binary Coded Decimal) numbers are integers and consist of 18 decimal digits and a sign.

Decimal digits are coded, two digits per byte.


EXAMPLE: Since there are two digits, each one gets four bits (nybble) and can encode 0000 - 1111(binary) or 0 - 15 (decimal). That works because we only have 0 - 9 to encode. Therefore the value 12 (decimal) becomes 0001 0010 = '1' and '2'.
There is also a sign in the left most byte. That is 10 bytes that are required to for a single BCD value. You can declare a single BCD value with the DT directive.
A       DT      -12345
  
The declaration above will produce the following in memory:



©2004, Gary L. Burt