Loading, please wait...

A to Z Full Forms and Acronyms

What is Microsoft intermediate language? What important role it plays in .NET environment?

Jul 09, 2020 Microsoft intermediate language, 16712 Views
In this article you will learn about What is Microsoft intermediate language? What important role it plays in .NET environment?

What is Microsoft intermediate language? What important role does it play in the .NET environment?

Microsoft intermediate language (MSIL)

Microsoft Intermediate Language (MSIL) is the assembly language output by .NET compilers-C#, VB.NET, etc.

.NET framework is shipped with compilers of all programming languages to develop programs. There are separate compilers for the visual basic, C#, and visual programming languages in .NET framework. Each .NET compiler produces an intermediate code after compiling the source code. The intermediate code after compiling the source code. The intermediate code is common for all environments. This intermediate code is known as Microsoft intermediate language (MSIL).

MSIL file is an executable file that can be transferred across various machines. Therefore, it is said that MSIL files are portable to any machine.

Thus the source code written by a programmer or user is compiled and converted into intermediate code. All the code of .NET compliant programming languages are converted into MSIL by their compilers like all managed code compilers for Microsoft .NET generate MSIL.

MSIL is machine independent and can be efficiently compiled into native code. The CLR has a just in time (JIT) compiler which converts the MSIL code into native machine code. Thus, before executing on CPU, MSIL must be translated by a JIT compiler. There is a JIT compiler for each machine architecture supported. The same MSIL will run on any supported machine.

So, .NET programs are compiled twice. During the first compilation process, the source code is converted into MSIL, which is machine-independent. It is stored in the files on the system. During the second compilation process, the MSIL file is executed and CLR transforms it into machine code.

Thus the Microsoft intermediate language (MSIL or simply IL) is the language into which code written with framework gets pre-compiled. The point of MSIL is to provide a CPU- independent instruction set. This way, code can be deployed on a varying number of platforms and efficiently converted to native code for a given platform by the runtime. Along with the MSIL, compilers create the metadata that describes the types, members, and code references for the given compiled code. This metadata helps the runtime do things like enforce security, locate and load class, and generally describe the code’s interaction with the runtime

Role of MSIL in a .NET environment

1. Platform Independence:-

Platform independence means that the same file containing byte code instruction can be placed on any platform; at runtime, the final stage of compilation can then be easily accomplished so that the code can run on that particular platform. In other words, MSIL defines a set of portable instructions that are independent of any specific CPU.

2. Performance Improvement:-

Instead of compiling the entire application at once, the JIT compiler simply compiles each portion of code as it is called just in time. When code has been compiled once, the resultant native executable is stored until the application exists so that it does not need to be recompiled the next time that portion of the code is run. This process is more efficient than compiling the entire application code at the start. This shows that the execution of the MSIL code will be almost as fast as executing native machine code.

3. Language Interoperability:-

The use of MSIL facilitates language interoperability. One can compile to MSIL from one language, and this compiled code should then be interoperable with code that has been compiled to MSIL from another language. In other words, MSIL architecture enables the framework to be language neutral. To a large degree, language choice is no longer dictated by the preference of the developer or the team. One can even mix languages in a single application. A class and an exception are thrown in a C#method that can be caught in a VB method.

4. Reducing maintenance headaches:-

MSIL code can be analyzed by the CLR to determine compliance with requirements such as type safety. Things like buffer overflows and unsafe casts can be caught at compile-time, greatly reducing maintenance headaches.

A to Z Full Forms and Acronyms

Related Article