views:

60

answers:

1

Was wondering how to inline a usage of fbstp on a 32 bit I86 architecture. I tried something like

int main( )
{
    double foo = 100.0;

    long bar = 0;

    asm( "pushl %1; fbstp %0"
         : "=m"(bar)
         : "r"(foo)
       );

    ...

But bar is unchanged. I have tried reading everything I can find on this but most example simply do things like add two integers together. I can’t find any that talk about pushing operands onto the stack and what I should be doing when an instruction like fbstp writes 80 bits of data back to memory ( i.e. what C type to use ) and how to specify it in the asm syntax.

Also on x86-64 there seems to be a pushq and no pushl but fbstp still exists whereas fbstq does not. Is there some other magic for 64 bit.

+1  A: 

There's an example here: http://bap.ece.cmu.edu/download/bap-0.1/VEX/test/test-i386.c

which seems to suggest doing something like this:

unsigned short bcd[5];
double a;

asm("fbstp %0" : "=m" (bcd[0]) : "t" (a) : "st");
Paul R
Thanks that does the trick
David HUnter