Hi,
I want to save FPU ST0 content to GPR32
int i;
float f;
fld dword [ f ]
push eax ;placeholder
fistp dword [ esp ]
pop eax
mov [ i ], eax
is it ok?
save FPU ST0 to GPR32
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: save FPU ST0 to GPR32
There are no "int" and "float" datatypes in assembly AFAIK. And I'm pretty sure ST0 is an 80-bit register, not a 32-bit one.
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: save FPU ST0 to GPR32
You're not saving the contents, you're saving the value. And it can be done better.Code: Select all
fld dword [ f ] push eax ;placeholder fistp dword [ esp ] pop eax mov [ i ], eax
Code: Select all
fld dword [f]
fistp dword [esp-4] ; placeholder
mov eax, dword [esp-4]
mov dword [i], eax
Re: save FPU ST0 to GPR32
What if there is an interrupt between fistp and mov? Then [esp-4] is thrashed. A better solution would beCraze Frog wrote:I am assuming you really need to get it to the register before putting it into i.Code: Select all
fld dword [f] fistp dword [esp-4] ; placeholder mov eax, dword [esp-4] mov dword [i], eax
Code: Select all
push eax ; push dummy value
fistp dword ptr [esp+0]
pop dword ptr [i]
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: save FPU ST0 to GPR32
Nice, except that it's slower and also doesn't save FPU ST0 to GPR32 (which was vital to the question). If all he wanted to was to get ST0 into an integer memory location he would fistp it directly to the memory location like this:A better solution would be
Code: Select all
fld dword [v_f]
fistp dword [v_i]
Re: save FPU ST0 to GPR32
well, it's part code of my compiler for something like
int i;
flloat f;
i = (int) f;
I use it to draw bezier curve, it works well on real machine.
I don't get any stack corruption, as the placeholder ensure the correct value.
int i;
flloat f;
i = (int) f;
I use it to draw bezier curve, it works well on real machine.
I don't get any stack corruption, as the placeholder ensure the correct value.