UMBC | CMSC 313 -- FPU Data | Previous | Next |
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:
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
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:
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.
A DD -1.23 ; A negative short fp number B DD 54E23 ; A positive short fp number C DD -5432 ; A negative long integer E DQ -1.23 ; A negative long fp number D resd 1 ; A variable which can hold either a short fp or long integer
Decimal digits are coded, two digits per byte.
A DT -12345