Hi Guys,

I'm having some trouble figuring out how real32 variables work.

Here's my though process after reading Randall Hyde's fantastic book, AOA:
-------------------------------------------------------------------------------------------------------------
1. Single-precision float variables use 8-bits to represent the exponent in excess-127 format.
2. The normalized form of 1.0 has an exponent of 2**0; therefore the 8-bit representation of the exponent should be $7F.
4. Together with the mantissa, 1.0e+0 should be represented as $7F80_0000.
-------------------------------------------------------------------------------------------------------------

If I assign the value 1.0 to a real32 variable, and print it, it is displayed as $3F80_0000.

Why??

Thanks Guys.

p.s. Here's my code:

-------------------------------------------------------------------------------------------------------------
program labEx;
#include("stdlib.hhf")
static
realVar: real32;
begin labEx;
stdout.put(nl, "Enter a 32-bit real number: ");
stdin.get(realVar);
mov(realVar, eax);
stdout.put(nl, "Number as real number: ", realVar, nl, "Number as hexadecimal: ", (type dword realVar));
end labEx;
-------------------------------------------------------------------------------------------------------------
Posted on 2003-07-15 10:52:07 by Jaysen
Remember that the exponent occupies bits 23..30 of the real32 value. If you convert $3F80_0000 to binary, you get:

%0011_1111_1000_0000_...._0000

Note that bits 23..30, when extracted and placed in a byte by themselves, forms $7F, which is +127, or 2**0 in a bias-127 format.
Cheers,
Randy Hyde
Posted on 2003-07-15 16:54:13 by rhyde
The exponent is shifted to the right by one bit in order to make room for the sign bit.

A nonzero number's most significant bit is always 1, so it disappears to make room for the shifted 8-bit exponent.
Posted on 2003-07-15 17:01:58 by tenkey
Jaysen,

Different ways of explaining can often help in reinforcing the understanding of basic principles. You may want to also have a look at a new tutorial (in progress) where the floating point formats are covered in Chapter 2. Hope it helps.

http://www.masmforum.com/website/tutorials/fptute/index.html

Raymond
Posted on 2003-07-15 22:44:45 by Raymond
Yes...yes...of course! The exponent is represented by bits 23 to 30 ( I was counting 24 to 30 - fool!!)

My warmest thanks to all the incredible computer Gurus of Win32Asm: *THE* Randall Hyde, tenkey, and Raymond!
Posted on 2003-07-16 03:18:30 by Jaysen