Search code examples
assemblybinarynumbersx86-16real-number

How do you translate the fractional part of a short real number as returned by the 8087 co-processor?


I've written a simple program that loads pi into the top of the register stack in the 8087, then it returns that constant into a short real memory variable.

FLDPI                     ;load pi
FSTP DWORD PTR shortReal  ;store pi in memory, then pop stack

The value stored in shortReal is 40 49 0F DB hex. This translates to 0100000001001001111111011011 in binary.

First bit is 0, so it's a positive number. The biased exponent portion translates to 1.

So, the actual number looks like this:

1(implied point)10010010000111111011011

1(implied point)1 translates to 3. , so that's the correct whole number portion of PI, but my understanding breaks down after this point.

Now the following number is left over:

0010010000111111011011

001 could translate to 1, which would be correct. However, that means that the next number would be 001, which would be 1 again, which is wrong, or it could be 0010, which equals 2, but that is wrong too.

How do you separate out each digit in the fractional portion.


Solution

  • No it's not how you calculate... As you move towards right from the decimal point. The accuracy increases.

    Calculate using this formula Consider the n value to decrease like -1 -2 -3 ...

    Now Decimal value = 0*2^-1 + 0*2^-2 + 1*2^-3 + 0*2^-4 + 0*2^-5 + 1*2^-6 etc until the end