Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Common Intermediate Language
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Example== Below is a basic [["Hello, World!" program]] written in CIL assembler. It will display the string "Hello, world!". <syntaxhighlight lang="csharp"> .assembly Hello {} .assembly extern mscorlib {} .method static void Main() { .entrypoint .maxstack 1 ldstr "Hello, world!" call void [mscorlib]System.Console::WriteLine(string) ret } </syntaxhighlight> The following code is more complex in number of opcodes. ''This code can also be compared with the corresponding code in the article about [[Java bytecode]].'' <syntaxhighlight lang="csharp"> static void Main(string[] args) { for (int i = 2; i < 1000; i++) { for (int j = 2; j < i; j++) { if (i % j == 0) goto outer; } Console.WriteLine(i); outer:; } } </syntaxhighlight> In CIL assembler syntax it looks like this: <syntaxhighlight lang="cpp"> .method private hidebysig static void Main(string[] args) cil managed { .entrypoint .maxstack 2 .locals init (int32 V_0, int32 V_1) ldc.i4.2 stloc.0 br.s IL_001f IL_0004: ldc.i4.2 stloc.1 br.s IL_0011 IL_0008: ldloc.0 ldloc.1 rem brfalse.s IL_001b ldloc.1 ldc.i4.1 add stloc.1 IL_0011: ldloc.1 ldloc.0 blt.s IL_0008 ldloc.0 call void [mscorlib]System.Console::WriteLine(int32) IL_001b: ldloc.0 ldc.i4.1 add stloc.0 IL_001f: ldloc.0 ldc.i4 0x3e8 blt.s IL_0004 ret } </syntaxhighlight> This is just a representation of how CIL looks near the [[virtual machine]] (VM) level. When compiled the methods are stored in tables and the instructions are stored as bytes inside the assembly, which is a [[Portable Executable]] (PE).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)