CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Assembly
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Assembly Questions and Answers for Assembly here!

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old February 15th, 2005, 07:04 AM
    mdale9 mdale9 is offline
    Junior Member
     
    Join Date: Feb 2005
    Posts: 3
    mdale9 is an unknown quantity at this point (<10)
    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.
    Reply With Quote
      #2    
    Old February 15th, 2005, 07:57 AM
    Bob Davis Bob Davis is offline
    Member +
     
    Join Date: Jan 2001
    Posts: 588
    Bob Davis has a spectacular aura about (150+)Bob Davis has a spectacular aura about (150+)
    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?
    Reply With Quote
      #3    
    Old February 15th, 2005, 08:24 AM
    jwbarton jwbarton is offline
    Member
     
    Join Date: Jan 2001
    Posts: 227
    jwbarton is a jewel in the rough (200+)jwbarton is a jewel in the rough (200+)jwbarton is a jewel in the rough (200+)
    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
    Reply With Quote
      #4    
    Old February 15th, 2005, 08:27 AM
    Andreas Masur Andreas Masur is offline
    Moderator
    Power Poster
     
    Join Date: May 2000
    Location: KY, USA
    Posts: 18,610
    Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)
    Re: MSVC inline assembly query

    [ Moved thread ]
    __________________
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Assembly


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 11:51 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009