Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:10:26+00:00 2026-05-28T15:10:26+00:00

I am using MS Visual Studio (2005, but that should not be important). I

  • 0

I am using MS Visual Studio (2005, but that should not be important).
I have a function whose body is implemented (necessarily) in inline assembly:

double f(double x)
{
    __asm{ ...body code... }
}

The assembly code finishes with the result to be returned contained in ST0.
The calling convention being used is __cdecl, so the convention is that a return double value is returned in ST0. Thus, after the __asm{…body code…} code is completed, the function is ready to have its returning stack-cleanup code run and ret. However, the code above will not compile, of course, because there is no “return dblVal;” statement. It could be corrected by changing the code to:

double f(double x)
{
    double dRet;
    __asm{ ...body code... }
    __asm{ fst dRet }
    return dRet;
}

but this has two disadvantages:
(1) the store to dRet is immediately followed by fld dRet, which is a complete waste and unnecessary (and this is being used innumerable times in a monte-carlo routine, so every cycle counts)
(2) more importantly, the value in ST0 has been carefully computed in the body to 64-bit-mantissa accuracy, which I need to preserve, and the fst followed by fld completely kills this.

How can I tell the VisualStudio compiler that the double to be returned is already in ST0?
I could write the exit code explicitly:

double f(double x)
{
    __asm{ ...body code... }
    __asm{ __asm leave
           __asm ret
         }
    return 0.0; //dummy code that is never executed, to make the compiler happy
}

but then one has to know the entry code that that the compiler generates (and in fact, the exit code above is wrong). So we could take this further, and write both the entry code and the exit code:

__declspec ( naked ) double f(double x)
{
    __asm{ ...entry code...}
    __asm{ ...body code... }
    __asm{ ...exit code... }
    return 0.0; //dummy code that is never executed, to make the compiler happy
}

but that is all VERY ugly. So, how do I get the compiler to look after the entry code and exit code, and tell it that the return value is already in ST0?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:10:28+00:00Added an answer on May 28, 2026 at 3:10 pm

    Actually, the answer to my question is that I was wrong about one thing in the statements of the question above:

    double f(double x)
    {
        __asm{ ...body code... }
    }
    

    without any return statement, with the __asm statements in the body, compiles just fine, without any errors or warnings. The compiler assumes (correctly) that I have arranged for the return values to be passed/returned appropriately. The compiler correctly generates the entry and exit codes and is happy leaving the rest to me. Go figure – why did I think I had tested that and found compile errors? Sigh. Sorry for bothering everyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to call the HttpServerUtuility.URLDecode function in C# using Visual Studio 2005, but
We have a native C++ Win32 .exe built using Visual Studio 2005 that works
Using Visual Studio 2005, I wrote a simple DLL in C that uses the
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being
I'm using Visual Studio 2005. I have a program written in C#. When I
I use visual studio 2005 , but recently I've heard that there is a
I am making a program, in C++ using Visual Studio 2005, that needs to
I have a MOSS solution successfully created in Visual Studio 2005 using VseWss 1.1
Im keen on learning javascript and ui design. Im using visual studio 2005 but
I've have been using Visual Studio 2005, alongside Visual Web Developer 2008 to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.