Module 16 - IL .NET |
Intermediate Language |
Assembly Language to Write Program |
Programming Language Neutral | |
Code Snippet | |
IL | .assembly MyApplication {} .method static void Main() { .entrypoint ret } |
Object Oriented, Stack Oriented etc. : Feature | |
Low Level, Block Structured, Case Sensitive and Free-Form Language |
Program |
Set of Instructions to Perform Task |
Combination of Tokens, Comments and White Spaces | |
Code Snippet | |
IL Program | /* File : MyProgram.il */ .assembly extern mscorlib {} .assembly MyApplication { .ver 1:0:0:0 } .module MyApplication.exe .subsystem 3 .corflags 1 .namespace MyNamespace { .class private auto ansi MyClass extends [mscorlib]System.Object { .method private hidebysig static void Main(class [mscorlib]System.String[] myParameters) cil managed { .entrypoint .maxstack 1 ldstr "Hello, World" // Write to Console call void [mscorlib]System.Console::WriteLine(class [mscorlib]System.String) ret } .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { .maxstack 1 ldarg.0 // Call a Constructor call instance void [mscorlib]System.Object::.ctor() ret } } } |
.assembly, extern, MyApplication, .ver, .module, MyApplication.exe, .namespace, MyNamespace, .class, .private, auto, ansi, MyClass, extends, .method, private, hidebysig, static, Main, class, myParameters, cil managed, .entrypoint, .maxstack, ldstr, call, ret, public, specialname, rtspecialname, instance, .ctor, ldarg.0 etc. : Token /* File: MyProgram.il */, // Write to Console, // Call a Constructor : Comment Space Character, Tab Character, New Line Character : White Space | |
Traditional Program to Display a Line of Text Hello, World |
Token |
Smallest Element of Program |
Recognized by the Assembler | |
Code Snippet | |
IL Token | Directive, Attribute, Identifier, Instruction, Label etc. |
.assembly, .ver, .module, .subsystem, .corflags, .namespace, .class, .method, .entrypoint, .maxstack : Directive Token extern, private, auto, ansi, extends, hidebysig, static, class, cil managed, public, specialname, rtspecialname, instance : Attribute Token MyAssembly, MyApplication.exe, MyNamespace, MyClass, Main, myParameters, .ctor : Identifier Token ldstr, ldarg.0, call, ret : Instruction Token | |
Comment and White Space are Separator, Not Token |
Comment |
Enhance Understanding of Program |
Ignored by the Assembler | |
Code Snippet | |
IL Comment | /* File : MyProgram.il */ // Write to Console // Call a Constructor |
/**/ : Multi Line Comment // : Single Line Comment | |
Play Important Role, In the Maintenance of Program |
White Space |
Enhance Readability of Program |
Extra White Spaces Ignored by the Assembler | |
Code Snippet | |
IL White Space | Space Character, Tab Character, New Line Character etc. |
Space Character : Space White Space Tab Character : Tab White Space New Line Character : New Line White Space | |
To Act as Token Separator, At Least One White Space Character |
Directive |
Declarations of Program like Creating Class or Method etc. |
IL Directive to the Assembler | |
Code Snippet | |
IL Directive | .assembly, .ver, .module, .subsystem, .corflags, .class, .method, .entrypoint, .maxstack etc. |
.assembly : Assembly Directive .ver : Version Directive .module : Module Directive .subsystem : Subsystem Directive .corflags : COR Flags Directive .namespace : Namespace Directive .class : Class Directive .method : Method Directive .entrypoint : Entry Point Directive .maxstack : Maximum Stack Directive | |
Remember, Starts with Period . Character |
Attribute |
Features of Program like Accessiblity, Inheritance, Interoperability etc. |
IL Attribute to the Assembler | |
Code Snippet | |
IL Attribute | extern, private, auto, ansi, extends, hidebysig, static, class, cil managed, public, specialname, rtspecialname, instance etc. |
extern : External Attribute private : Private Attribute auto : Auto Attribute ansi : ANSI Attribute extends : Extends Attribute hidebysig : Hide By Signature Attribute static : Static Attribute class : Class Attribute cil managed : CIL Managed Attribute public : Public Attribute specialname : Special Name Attribute rtspecialname : Runtime Special Name Attribute instance : Instance Attribute | |
Remember, Don't Modify the Output of Program |
Instruction |
Operations of Program like Call a Function etc. |
IL Instruction to the Assembler | |
Code Snippet | |
IL Instruction | ldstr, ldarg.0, call, ret etc. |
ldstr : Load String Instruction ldarg.0 : Load Argument Instruction call : Call Instruction ret : Return Instruction | |
Remember, Starts without Period . Character |