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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:07:14+00:00 2026-06-05T23:07:14+00:00

I’m converting code to IL (CIL/MSIL, etc.) from C#. I’m stuck on the conditionals

  • 0

I’m converting code to IL (CIL/MSIL, etc.) from C#. I’m stuck on the conditionals because I want to be able to store to the next available free location. Example:

var x = 0;
if(x > 20)
 x = 1;

Console.WriteLine(x);

If I convert this to what I believe is correct IL, I get:

IL_0001:  ldc.i4.0    
IL_0002:  stloc.0     
IL_0003:  ldloc.0     
IL_0004:  ldc.i4.s    14 
IL_0006:  cgt         
IL_0008:  ldc.i4.0    
IL_0009:  ceq         
IL_000B:  stloc.1     
IL_000C:  ldloc.1     
IL_000D:  brtrue.s    IL_0011
IL_000F:  ldc.i4.1    
IL_0010:  stloc.0     
IL_0011:  ldloc.0     
IL_0012:  call        System.Console.WriteLine

I believe this to be correct IL, but my example is very static. If you see in the IL code, it stores the result of ceq into loc.1

And thus is my issue–the compiler saw that loc.0 was already taken(the variable ‘x’) and used the next free location, which was 1. My goal is to do this dynamically where a given method could have N variable before the conditional.

So, finally, here is my question:
How do I, from C#, emit an opcode to say “stloc.nextAvailable” and it’s equivalent load?

  • 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-05T23:07:15+00:00Added an answer on June 5, 2026 at 11:07 pm

    To me it looks like you’re looking at IL generated while compiling for debug mode, the stloc.1 and ldloc.1 are referencing a local that doesn’t exist in your code but may be created to give the nice little tooltip while hovering over the greater than symbol while debugging.

    I would expect release mode generated IL to look more like this (if it were to not optimize the whole thing down to Console.WriteLine(0); in advance):

    //load the 4-byte integer 0 on to the stack
    IL_0001:    ldc.i4.0
    //set the value of local 0 (x) to the previous value on the stack (0)
    IL_0002:    stloc.0
    //load up x for the comparison
    IL_0003:    ldloc.0
    //load the 4-byte integer 0x14 (20) on to the stack
    IL_0004:    ldc.i4.s    14
    //check to see whether two elements back on the stack is greater than one element back on the stack (x > 20), push 1 one back on the stack in the case the first is greater, 0 otherwise
    IL_0005:    cgt
    //if 0x14 (20) was the greater (or equal) value, jump over the body of the if block
    IL_0006:    brfalse.s    IL_0009
    //load the 4-byte integer 1 (1) on to the stack
    IL_0007:    ldc.i4.1
    //set the value of local 0 (x) to the previous value on the stack (1)
    IL_0008:    stloc.0
    //load the value of local 0 (x) on to the stack
    IL_0009:    ldloc.0
    //call Console.WriteLine
    IL_000A:    call    System.Console.WriteLine
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.