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 8503307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:43:21+00:00 2026-06-11T01:43:21+00:00

I cannot find a similar question/answer either here on SO or on the internet,

  • 0

I cannot find a similar question/answer either here on SO or on the internet, and as useless as this question maybe it is a question that came to my mind whilst doing some reading on MSIL. I am very curious to understand how IL operation execution works in my scenario, even if this is not a practical question I have no one else to ask.

Premise:

Bearing in mind that the execution of both MSIL commands and functions is done in three steps:

  1. Push command operands or function parameters onto the stack.
  2. Execute the MSIL command or call function. The command or function pops their operands (parameters) from the stack and pushes onto the stack result (return value).
  3. Read result from the stack.

Steps 1 and 3 are optional. For example, the void function doesn’t push a return value to the stack.

I understand that it is what a method does that determines how much ‘processing-power’ is required, but for the sake of my curiosity lets consider these two very basic methods:

First method:

void Method1()
{
  var result = 1+1;
}

Second method:

int Method2()
{
  var result = 1+1;
  return result;
}

Question:

Because the void method doesn’t push a return value (or is there an implicit return) does this mean that it requires less overhead when executing as opposed to the second method?

  • 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-06-11T01:43:22+00:00Added an answer on June 11, 2026 at 1:43 am

    Remember, though, that MSIL is not executed or even interpreted. MSIL is an expression of the compiled code as it would be executed on the virtual machine. But the JIT compiler converts MSIL to machine code (x86, etc.). The x86 is fundamentally different from the stack-based virtual machine.

    At the most basic level, functions return values in registers. Assuming that the registers are large enough. Let’s stick with 64-bit values (references, long integers, doubles, and smaller value types). Those can be returned in the RAX register. In your trivial example, there would be no difference in the generated machine code for the two functions. That is, Method1 would be:

    mov rax, 1
    inc rax
    ret
    

    (And, yes, I know that a smart compiler would collapse 1+1 to 2. Let’s assume that there was a memory access there, okay?)

    Method2 would be identical because the value to be returned is already in the RAX register.

    So when you’re working with 64 bit or smaller quantities, the difference between a method that returns a value and a method that doesn’t return a value will most often differ, if at all, only in whatever instruction it takes to load the return value into the proper register. This is typically a single mov instruction. It’s going to depend on the order in which things are done, and also on how well the compiler and JITer optimize things.

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

Sidebar

Related Questions

I have searched through similar questions on here, and cannot find an exact answer.
A question similar to this has been posted several time, but I cannot find
Similar questions have been asked but cannot find a solution that works well. What
I realize there are similar questions on this topic, but I still cannot find
I cannot find the solution for this problem, here is the simplified example: On
I cannot find EntityConfiguration. The same question for RC was here but I thought
Here is the reason why this question was being asked: www.devplusplus.com/Tests/CSharp/Hello_World . While similar
I have looked into this and cannot find a suitable answer. I want to
I have not been able to find a similar answer to my question. Situation:
I have a question very similar to this one but the answer does not

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.