flat assembler
Message board for the users of flat assembler.

Index > Main > fpu fild

Author
Thread Post new topic Reply to topic
b1528932



Joined: 21 May 2010
Posts: 287
b1528932 07 Mar 2011, 19:22
i have used a fild instruction to load a set of variables:
Code:
finit

fild [_ld0]
fild [_ld1]
fild [_ld2]
fild [_ld3]
fild [_ld4]
fild [_ld5]
fild [_ld6]
fild [_ld7]


fsave [_ww]

_ld0 dq 1
_ld1 dq 2
_ld2 dq 3
_ld3 dq 4
_ld4 dq -1
_ld5 dq 0
_ld6 dq -3
_ld7 dq -4

    



my debug returned me this:
Code:
C0018000000000000000
C000C000000000000000
00000000000000000000
BFFF8000000000000000
40018000000000000000
4000C000000000000000
40008000000000000000
3FFF8000000000000000    


i dont get it. can someone explain me this representation?
i read that highest bit is sign [ok], next 15 bits are exponent [not ok] and the rest is mantisa.
lets take -3 - its C000C000000000000000.

1 100000000000000 110000000000...
sign ok, exponent is 1, mantisa 3. -3*2^0

-4 is C0018000000000000000.
1 100000000000001 100000...
sign ok, mantisa 1, exponent how much? shuld be 2. but its not 2, its something else... it is 1 since 100.. is 0?


4 is 40018000000000000000.
0 100000000000001 1000...

same here. i dont get it, how its done.


lets take a rnadom number, C03C83D17DC7833EDC28

sign:1
exponent: 100000000111100 (16444)
mantisa: 10000011110100010111110111000111100001101111101101110000101000 (0.2374627846254418984)
0.2374627846254418984 * 2^16444 = ???


C02A8000000000000000
1 100000000101010 10000000
sign 1, exponent
exponent 16426, mantisa 1. 1*2^16426 = propably ok.



i dont understand it...
Post 07 Mar 2011, 19:22
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
ProphetOfDoom 07 Mar 2011, 23:01
I think the FPU assumes that 3FFF has been added to the exponent (it's called a "biased" exponent). So to get the real exponent value, you subtract 3FFF from the exponent value your debugger is showing you. Your calculations should all work out then. (The bias is different for qwords and dwords). I got this from:

http://www.website.masmforum.com/tutorials/fptute/fpuchap2.htm#real10
Post 07 Mar 2011, 23:01
View user's profile Send private message Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932 08 Mar 2011, 10:26
thank you, but i managed to understand it myself.

when you have a float representation
SEEEEEMMMMMMMMMM

its real value is equivalent to:

sign tells if its + or -, nothing more, just sign.
E is exponent. MSB = 0, rest = 1 (0111111...) is 0. in order to convert to real number, you have to add it (depends on ammount of exponent bits).
For example is you have 7 exponent bits, 0 is 0111111, 1 is 1000000, 2 is 1000001, and so on. -1 is 0111110, etc.

M is mantisa.
lets say exponent is 1000101 (1000101 - 0111111 = 110 (6)).
mantisa is 011010 (22).
real number is
0 * 2^6 = 0
1 * 2^5 = 32
1 * 2^4 = 16
0 * 2^3 = 0
1 * 2^2 = 4
0 * 2^1 = 0

32+16+4 = 52. sign is 0, so +52.

lets check in bochs:
+52
4004D000000000000000

0 100000000000100 1101000000000...

exponent = 100000000000100 - 011111111111111 = 101 (5)
mantisa = 11


1 * 2^5 = 32
1 * 2^4 = 16
0 * 2^3 = 0
1 * 2^2 = 4
0 * 2^1 = 0
0 * 2^0 = 0
0 * 2^-1 = 0
0 * 2^-2 = 0
0 * 2^-3 = 0
0 * 2^-4 = 0
...
0 * 2^-58 = 0



32 + 16 + 4 = 52
Post 08 Mar 2011, 10:26
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.