1

What is this symbol ( IL_0000 etc) in the IL code. its this the real memory heap address?

  IL_0000:  nop
  IL_0001:  ldstr      "here is something"
  IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
  IL_000b:  nop
  IL_000c:  ldc.i4.s   18
  IL_000e:  newobj     instance void Proj.Stock::.ctor(int32)
  IL_0013:  stloc.0
  IL_0014:  ldstr      "another"
  IL_0019:  call       void [mscorlib]System.Console::WriteLine(string)
  IL_001e:  nop
  IL_001f:  ldstr      "and even more"
  IL_0024:  call       void [mscorlib]System.Console::WriteLine(string)
  IL_0029:  nop
  IL_002a:  ret
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
RollRoll
  • 8,133
  • 20
  • 76
  • 135

1 Answers1

4

The IL_0000: is a Code Label. It's really just an identifier so you can easily reference jump locations by name instead of by byte count.

See the Common Language Infrastructure (CLI) standard documents. ECMA-335 section II.5.4

II.5.4 Labels and l ists of labels

Labels are provided as a programming convenience; they represent a number that is encoded in the metadata. The value represented by a label is typically an offset in bytes from the beginning of the current method, although the precise encoding differs depending on where in the logical metadata structure or CIL stream the label occurs.

...

Matthew Whited
  • 22,160
  • 4
  • 52
  • 69
  • 3
    It also has the interesting side effect of showing you the size of every instruction (since the numbers are relative addresses). – Frédéric Hamidi Jun 21 '16 at 19:04
  • True... if you are using ILDASM... but that's not a requirement. – Matthew Whited Jun 21 '16 at 19:05
  • @FrédéricHamidi - So at label `IL_0001`, its doing a `ldstr` on the string `here is something`. The next label is `IL_0006`. However, `here is something` is 17 characters long and stored as unicode (2 bytes per character), that's 34 bytes. So shouldn't the next label be `IL_0023` (35 in hex)? – Icemanind Jun 21 '16 at 19:20
  • 1
    A reference to the string is stored after the opcode. Not the string its self. – Matthew Whited Jun 21 '16 at 19:21
  • @MatthewWhited - Gotcha! Thanks for clearing that up. – Icemanind Jun 21 '16 at 19:38
  • It's the same reason the `call` opcodes are 5 bytes long. They also use a 32bit reference to the method and not the method name. – Matthew Whited Jun 21 '16 at 19:56