flat assembler
Message board for the users of flat assembler.

Index > Main > FPU Questions.

Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 22 Nov 2011, 21:10
hello everyone, recently I've started learning some FPU. I have some questions about it.
1) is there any way to convert unsigned to signed integer ? example what I mean:
Code:
;check if sqrt will be int..
x dd 90
fild dword[x]
fsqrt
fistp dword[x] ;here
fild dword[x] ;and here.
fmul st0,st0
sub esp,4
fistp dword[esp]
mov eax,dword[x]
mov ecx,dword[esp]
add esp,4
cmp eax,ecx
jne ...    

2) is there any instruction that will allow me to write near integer instead of float ? for example:
Code:
;sin 90
x dd 90
fild dword[x]
fsin ;st0 = 0.8939966636005578905
fistp dword[x] ;here, x should be 1 instead of 0 and float number, because 0.8 ~= 1    

3) which instruction clears fpu stack without storing it somewhere ? (fld/fild)
Thank you Wink
Post 22 Nov 2011, 21:10
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 22 Nov 2011, 21:57
The FPU has 4 possible rounding modes that can be configured using the control word (fldcw/fstcw) and applied using the frndint instruction. In some cases you will need to adjust the value before rounding e.g. ceiling/floor add/sub 0.5 before rounding.

The FPU only has signed representation but you can load a 32bit unsigned as a 64bit signed integer by padding the upper dword with 0; otherwise you have to explicitly convert the unsigned value in the FPU.

The instructions ending with "-p" pop from the FPU stack and in some cases double pop (fcompp); there is also the fdecstp and finstp instructions.
Post 22 Nov 2011, 21:57
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1620
Location: Toronto, Canada
AsmGuru62 22 Nov 2011, 22:10
FSIN parameter is in Radians (as per Intel Manual), so SIN 90 in your case is a sin(90 rads). That is why it is 0.8993...
Smile
A proper SIN(90) would be this one:
Code:
FLDPI
PUSH 2
FIDIV DWORD [ESP]
ADD ESP,4
FSIN
;
; NOW ST0 = SIN(90 degrees)
;
    

To pop the stack without storing is this:
Code:
FSTP ST0     ; Sweet! We're still storing!
    
Post 22 Nov 2011, 22:10
View user's profile Send private message Send e-mail Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 23 Nov 2011, 07:38
Thank you guys! Wink
Post 23 Nov 2011, 07:38
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.