MSIL conditional jump (simple annotation)

c# code:

Copy the code
using System;
public class aidd2008
{
public static void Main(String[] argv)
{
int x = 10;
int y = 6;
if (x > y)
{
Console.WriteLine(x);
}
else
{
Console.WriteLine(y);
}
Console.Read();
}
}
Copy the code

MSIL:

Copy the code
// =============== the CLASS the MEMBERS DECLARATION =================== .class public Auto ansi beforefieldinit aidd2008 the extends [mscorlib] System.Object { .method public hidebysig static void   the Main ( String [] the argv) CIL Managed   { .entrypoint // Code size 44 is (0x2C) .maxstack 2 .locals the init ( Int32 V_0, Int32 V_1, BOOL V_2) // define three variables IL_0000: nop IL_0001:













ldc.i4.s 10 // the integer value 10 Load Stack IL_0003: stloc.0 // the stack 10 just loaded is assigned to the first local variable, int X = 10 IL_0004: ldc.i4.6 / / the integer value 6 load stack IL_0005: stloc.1 // to just load the stack 6 is assigned to the second local variable, int Y = 6 IL_0006: ldloc.0 IL_0007: ldloc.1 // these two , the x, y two local variables load stack IL_0008: CGT // comparison x, y, size, results are saved at the top of stack (1 or 0 indicates results to true, to false) IL_000a: ldc.i4.0 / / the load stack 0 IL_000b: ceq // 0 and comparing the calculation result cgt are equal, the result will be stored at the top of the stack (results are true or 0. 1, to false) IL_000d: stloc.2 // calculation result of ceq save the bool variable









IL_000e: ldloc.2 // then the calculation result ceq Loading IL_000f: brtrue.s IL_001c // judgment jump, jump if explicit Y, not Skip explicitly X- IL_0011: NOP IL_0012: ldloc.0 IL_0013: Call void [mscorlib] :: the System.Console the WriteLine ( Int32 ) IL_0018: NOP IL_0019: NOP IL_001a: br. IL_0025 IL_001c: NOP IL_001d: ldloc.1 IL_001e: Call void [mscorlib] :: the System.Console the WriteLine ( Int32 ) IL_0023 : nop IL_0024: nop IL_0025:













call int32 [mscorlib]System.Console::Read()
IL_002a: pop
IL_002b: ret
} // end of method aidd2008::Main
Copy the code

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2012/08/25/2656780.html

Guess you like

Origin blog.csdn.net/weixin_33936401/article/details/93495216