dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: MSVC inline assembly query

  1. #1
    Join Date
    Feb 2005
    Posts
    3

    MSVC inline assembly query

    I am a bit of a newbie to assembly and only need to do one thing at present, which is access the FSINCOS operation on the x87 math co-processer. I have trawled the web and found a few references and have come up with the following code:


    void SinCos(double Angle, double *SinAns, double *CosAns) {
    __asm {


    fld QWORD PTR [Angle]
    fsincos
    fstp QWORD PTR [CosAns]
    fstp QWORD PTR [SinAns]
    fwait
    }
    }

    main()
    {

    double s=0.0;
    double c=0.0;
    double ang = 3.0;


    SinCos(ang,&s,&c); //call one version of the code


    //call the other one version of the code
    __asm {

    fld QWORD PTR [ang]
    fsincos
    fstp QWORD PTR [c]
    fstp QWORD PTR [s]
    fwait
    };

    }

    When I single step through it and look at the registers the operation is occuring as expected but only the second version pops the values into "c" and "s".

    I am using VC++ 6.0 Professional with the default compiler options:
    /nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/small_test.pch" /YX /Fo"Debug/"

    Please help.

  2. #2
    Join Date
    Jan 2001
    Posts
    588

    Re: MSVC inline assembly query

    I'm no expert in x86 assembly, so this could be pretty far off, but I notice one big difference in the two versions of the function you showed. In the first one, the symbols that you pass to the fstp instructions are already declared as pointers in your C code, while in your second version (the one that works), the symbols are plain old double variables.

    It seems, then, that in your assembly, you have an extra level of indirection. Instead of storing the result in the variable, you're altering the actual value of the pointer that you're passing to your SinCos function. I don't know exactly how to syntactically fix what you're seeing. Remove the "ptr" token in those lines of code, maybe?

  3. #3
    Join Date
    Jan 2001
    Posts
    253

    Re: MSVC inline assembly query

    Bob Davis is correct, you have an extra level of indirection.

    You need to do something like:

    Code:
    void SinCos( double ang, double* sinAns, double* cosAns )
    {
       _asm
       {
          fld QWORD PTR [ang]
          fsincos
          mov ebx,[cosAns]                     ; get the pointer into ebx
          fstp QWORD PTR [ebx]             ; store the result through the pointer
          mov ebx,[sinAns]
          fstp QWORD PTR [ebx]
       }
    }
    Best regards,
    John

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: MSVC inline assembly query

    [ Moved thread ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)