The released IL code is missing some lines. What is the task between the lines?

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint
  // Code size       9 (0x9)
  .maxstack  1
  .locals init ([0] class ConstReadOnly.second p)
  IL_0000:  nop
  IL_0001:  ldc.i4.5
  IL_0002:  newobj     instance void ConstReadOnly.second::.ctor(int32)
  IL_0007:  stloc.0
  IL_0008:  ret
} // end of method Program::Main

It IL_0002follows here IL_0007.
Can someone give me a real scenario that is happening here?

+4
source share
2 answers

These are just tags. There is no code between them. The label represents the offset from the start of the function in bytes.

offset_0:  nop      //size 1 byte
offset_1:  ldc.i4.5 // size 1 byte
offset_2:  newobj instance void ConstReadOnly.second::.ctor(int32) // size 5 bytes
offset_7:  stloc.0 // size 1 byte 
offset_8:  ret

You can easily change them and recompile them again.

+2
source

When I run ildasmin your code when specifying an option /BYTES, the output is:

.method private hidebysig static void  Main(string[] args) cil managed
// SIG: 00 01 01 1D 0E
{
  .entrypoint
  // Method begins at RVA 0x2048
  // Code size       9 (0x9)
  .maxstack  1
  .locals init (class ConstReadOnly.second V_0)
  IL_0000:  /* 00   |                  */ nop
  IL_0001:  /* 1B   |                  */ ldc.i4.5
  IL_0002:  /* 73   | (06)000003       */ newobj     instance void ConstReadOnly.second::.ctor(int32)
  IL_0007:  /* 0A   |                  */ stloc.0
  IL_0008:  /* 2A   |                  */ ret
} // end of method Program::Main

, . , , newobj, 5 , , .

, , . , #.

0

Source: https://habr.com/ru/post/1665020/


All Articles