ArticleslgStudy

engineering

Common Intermediate Language

Common Intermediate Language is a engineering topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Common Intermediate Language rather than just read about it. In short: Common Intermediate Language (CIL), formerly called Microsoft Intermediate Language (MSIL) or Intermediate Language (IL), is the intermediate language binary instruction set defined within the Common Language Infrastructure (CLI) specification. CIL instructions are executed by a CIL-compatible runtime environment such as the Common Language Runtime.

Key takeaways

  • Common Intermediate Language belongs to engineering; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Common Intermediate Language to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Common Intermediate Language from memory before moving on to harder problems.

Reference excerpt

Common Intermediate Language (CIL), formerly called Microsoft Intermediate Language (MSIL) or Intermediate Language (IL), is the intermediate language binary instruction set defined within the Common Language Infrastructure (CLI) specification. CIL instructions are executed by a CIL-compatible runtime environment such as the Common Language Runtime. Languages which target the CLI compile to CIL. CIL is object-oriented, stack-based bytecode. Runtimes typically just-in-time compile CIL instructions into machine code. CIL was originally known as Microsoft Intermediate Language (MSIL) during the beta releases of the .NET languages. Due to standardization of C# and the CLI, the bytecode is now officially known as CIL. Windows Defender virus definitions continue to refer to binaries compiled with it as MSIL.

General information During compilation of CLI programming languages, the source code is translated into CIL code rather than into platform- or processor-specific object code. CIL is a CPU- and platform-independent instruction set that can be executed in any environment supporting the Common Language Infrastructure, such as the .NET runtime on Windows, or the cross-platform Mono runtime. In theory, this eliminates the need to distribute different executable files for different platforms and CPU types. CIL code is verified for safety during runtime, providing better security and reliability than natively compiled executable files. The execution process looks like this:

Source code is converted to CIL bytecode and a CLI assembly is created. Upon execution of a CIL assembly, its code is passed through the runtime's JIT compiler to generate machine code. Ahead-of-time compilation may also be used, which eliminates this step, but at the cost of executable-file portability. The computer's processor executes the machine code.

Instructions

CIL bytecode has instructions for the following groups of tasks:

Load and store Arithmetic Type conversion Object creation and manipulation Operand stack management (push / pop) Control transfer (branching) Method invocation and return Throwing exceptions Monitor-based concurrency Data and function pointers manipulation needed for C++/CLI and unsafe C# code

Computational model The Common Intermediate Language is object-oriented and stack-based, which means that instruction parameters and results are kept on a single stack instead of in several registers or other memory locations, as in most programming languages. Code that adds two numbers in x86 assembly language, where eax and edx specify two different general-purpose registers:

Code in an intermediate language (IL), where 0 is eax and 1 is edx:

In the latter example, the values of the two registers, eax and edx, are first pushed on the stack. When the add-instruction is called the operands are "popped", or retrieved, and the result is "pushed", or stored, on the stack. The resulting value is then popped from the stack and stored in eax.

Object-oriented concepts CIL is designed to be object-oriented. One may create objects, call methods, and use other types of members, such as fields. Every method needs (with some exceptions) to reside in a class. So does this static method:

The method Add does not require any instance of Foo to be declared because it is declared as static, and it may then be used like this in C#:

In CIL it would look like this:

Instance classes An instance class contains at least one constructor and some instance members. The following class has a set of methods representing actions of a Car-object.

Creating objects In C# class instances are created like this:

And those statements are roughly the same as these instructions in CIL:

Invoking instance methods Instance methods are invoked in C# as the one that follows:

As invoked in CIL:

Metadata

The Common Language Infrastructure (CLI) records information about compiled classes as metadata. Like the type library in the Component Object Model, this enables applications to support and discover the interfaces, classes, types, methods, and fields in the assembly. The process of reading such metadata is part of reflective programming (reflection). Metadata can be data in the form of attributes. Attributes can be customized by extending the Attribute class. This is a powerful feature. It allows the creator of the class the ability to adorn it with extra information that consumers of the class can use in various meaningful ways, depending on the application domain.

Example Below is a basic "Hello, World!" program written in CIL assembler. It will display the string "Hello, world!".

The following code is more complex in number of opcodes. This code can also be compared with the corresponding code in the article about JVM bytecode.

In CIL assembler syntax it looks like this:

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).

Generation A CIL assembly and instructions are generated by either a compiler or a utility called the IL Assembler (ILAsm) that is shipped with the execution environment. Assembled CIL can also be disassembled into code again using the IL Disassembler (ILDASM). Other tools, such as .NET Reflector, can decompile CIL into a high-level programming language (e.g., C# or Visual Basic). This makes CIL a very easy target for reverse engineering. This trait is shared with JVM bytecode. However, there are tools that can obfuscate the code, and do it so that the code cannot be easily readable but still be runnable.

Execution

Just-in-time compilation Just-in-time compilation (JIT) involves turning the byte-code into code immediately executable by the CPU. The conversion is performed gradually during the program's execution. JIT compilation provides environment-specific optimization and assembly verification. To accomplish this, the JIT compiler examines the assembly metadata for any illegal accesses and handles violations appropriately.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Common Intermediate Language

Start with the simplest possible case. Write down what Common Intermediate Language claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In engineering, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Common Intermediate Language before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Common Intermediate Language ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Common Intermediate Language

In research
Common Intermediate Language appears in engineering research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Common Intermediate Language in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Common Intermediate Language is common in secondary-school and first-year university syllabi. It links to neighbouring topics Assembly languages, Bytecodes, Common Language Infrastructure, so understanding it makes those chapters shorter.
In everyday life
Look for Common Intermediate Language outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Common Intermediate Language” →

How to study Common Intermediate Language in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Common Intermediate Language means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Common Intermediate Language out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Common Intermediate Language in simple terms?

Common Intermediate Language (CIL), formerly called Microsoft Intermediate Language (MSIL) or Intermediate Language (IL), is the intermediate language binary instruction set defined within the Common Language Infrastructure (CLI) specification. CIL instructions are executed by a CIL-compatible runt…

Why does Common Intermediate Language matter?

Because it connects several engineering ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Common Intermediate Language?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Common Intermediate Language.

Tags

  • Assembly languages
  • Bytecodes
  • Common Language Infrastructure

Keep exploring