1 / 12

MSIL

MSIL. C# .NET Software Development. MSIL AKA CIL. What all .NET languages compile to Binary Intermediate Language check out: C:Program FilesMicrosoft Visual Studio .NET 2003SDKv1.1Tool Developers Guidedocs Partition II Metadata.doc Partition III CIL.doc StartDocs.htm.

ulema
Download Presentation

MSIL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MSIL C# .NET Software Development

  2. MSIL AKA CIL • What all .NET languages compile to • Binary Intermediate Language • check out: • C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Tool Developers Guide\docs • Partition II Metadata.doc • Partition III CIL.doc • StartDocs.htm

  3. Making MSIL Readable • ILDasm.exe • Disassembles MSIL to MSIL Assembly Language • ILAsm.exe • Assembles MSIL Assembly Language to MSIL

  4. MSIL: A Stack Machine • All operations are executed on the stack • Parameters • Variables • Return values • Expression evaluation • When a command is executed it: • pushes operands (parameters) on the stack • Executes the command or function • The called function pops its own parameters off the stack • The called function pushes it’s return value onto the stack (if needed) • Read the result from the stack (if available)

  5. Onto the Stack... • Value-types are placed directly on the stack • Reference-types place only the reference on the stack • (But you knew that already) • IL Commands: • ld (load: loads a value onto the stack) • st (store: stores a value in a variable and removes it from the stack)

  6. “Hello IL World” • .entrypoint • describes the function as the program entry point • .maxstack 1 • tells ilasm that the stack will only reach a depth of 1 • ldstr • loads a string onto the stack • call • calls the specified function • ret • returns from the function (clearing anything put on the stack)

  7. Loading an Integer • ldc.i4.7 • ldc: load constant • i4: 4-byte integer • 7: value 7 • stloc.0 • Pops the stack into the first local variable • Type has to match initialization type • for the first 4 locals you can say stloc.n (3 > n > 0) • for locals number 4 – 255, use stloc.s n • ldloc.0 • Loads local at index 0 onto the stack

  8. Doing Some Math • ldc.r4 (A4 AA 8A 40) • Loads the hex value as a 4-byte floating point • conv.r4 • converts the top value of the stack to r4 • add • adds the top values of the stack, removes them, pushes the result • sub • subtracts the top values of the stack

  9. Try if-else • bne.un.s IL_000f • branch (jump) if the top two operands are not equal • br.s IL_0012 • branch unconditionally • box • unbox • switch (next demo)

  10. Building Classes • Constructors • stfld • stores a field • Property • newobj • Creates a new object

  11. Exceptions • .try • catch • finally • callvirt • Calls a virtual function (or Property)

  12. Talk about GC!

More Related