I'm trying to get data from my FPU-Stack (say ST3 or ST0, doesn't matter) to any of the GPRs, say EBX or EAX. I know there's a way to get it from EAX to ST0:

FLD qword

Yet I cannot figure out how to do it the other way around. If it helps, I'm using nasm and Linux. Thanks in advance
Posted on 2003-07-08 11:29:39 by D'Espice
Hi D'Espice ,

to move it from the st-registers use FST(float-store) in one it's form.
like so:
>>fld dwrod ptr //loads the float 'somefloat'
>>fst dword ptr //stores st(0) in 'anotherfloat'

to load it into eax I think you need to use an intermediate variable, that is add a:
>>mov eax,anotherfloat

to the code above.

hope this helps :)

/edmund :)
Posted on 2003-07-08 12:20:03 by edmund
um... you mean that if eax has the value 123 you want to load this value to st0? or do you want to load the value at the memorylocation where eax points to?

you code

FLD qword [EAX]

loads the data where eax points to.
to get eax's value to st0 use the stack like this:

push eax ;eax to stack
fild [esp] ;value from stack ;load as [b]integer[/b]
;if you have to load more values do that now
add esp, n*4 ;correct the stack, where n is the count of numbers you loaded, don't forget this!

getting st0->eax goes similar:

sub esp,4
fistp [esp] ;store as [b]integer[/b]
pop eax
Posted on 2003-07-08 13:25:29 by hartyl
hartyl's suggestion to transfer the integer value of ST(0) into a CPU register is almost correct. I would normally use "push eax" instead of "sub esp,4" to reserve space on the stack, but that is immaterial.

What is missing is:

First, you have to specify the size of the integer you want to store in , otherwise the assembler will most probably return an error. A proper code should be "fild dword ptr "

Secondly, an FWAIT instruction must be inserted before you attempt to recover the value with the "pop eax" to insure that the FILD instruction has been completed. Otherwise, you risk retrieving junk (or the former value of EAX) with the "pop eax".

N.B. You could also transfer a REAL4 into EAX if you should have any need for it. Simply use the FLD instruction instead of the FILD one in the suggested code.

Posted on 2003-07-08 23:29:36 by Raymond
Originally posted by hartyl
you code

FLD qword [EAX]

loads the data where eax points to.

Errrr... dang you're right, I accidently copy&pasted the wrong instruction
So basically what I have to do is use the stack, right? Thanks a lot guys, I'm gonna give that a shot
Posted on 2003-07-09 03:38:15 by D'Espice