Search code examples
assemblydosinline-assemblyturbo-c++x87

asm ("fldl %0"...) in DOS, Intel syntax?


I'm working on a retro project trying to compile some test code in Borland Turbo C++/DosBox.

I have this function:

double sin(double x){
   asm ("fldl %0;"
        "fsin;"
        "fstpl %0" : "+m"(x));
   return x;
}

I figure it returns the sin value of x, but I'm otherwise lost.

The error is: Undefined symbol 'fldl'

Can anyone explain this function in Intel asm syntax?

I can't figure it out, I've only ever coded 16bit DOS asm code and no floating point.

Kind Regards /Jacob


Solution

  • The problem is that the target CPU must be at least 386.

    so the function should be:

    double sin(double x){
        asm{
            fld qword ptr [x]
            fsin
            fstp qword ptr [x]
        }
        return x;
    }
    

    I've gotten similar code to compile in TASM with .386 after .MODEL "size"