Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IL code vs IL assembly: is there a difference?

Tags:

c#

.net

If I run a .NET compiler it produces a file containing intermediate language code (IL) and put it into, an .exe file (for instance).

After if I use a tool like ildasm it shows me the IL code again.

However if I write directly into a file IL code then I can use ilasm to produce an .exe file.

What does it contain? IL code again? Is IL code different to IL assembly code?

Is there a difference between IL code and IL assembly?

like image 537
xdevel2000 Avatar asked Nov 05 '15 11:11

xdevel2000


People also ask

Is IL code in assembly language?

IL itself is in the binary format which means it can't be read by the human. But as other binary (executable) code have an assembly language, so in the same way IL also has an assembly language known as IL Assembly (ILAsm). IL Assembly has the instruction in the same way that the native assembly language has.

Is Assembly the same as machine code?

The main difference between machine code and assembly language is that the machine code is a language that consists of binaries that can be directly executed by a computer while an assembly language is a low-level programming language that requires a software called an assembler to convert it into machine code.

What is an IL code?

What is IL? Languages such as C# or Java are not directly compiled into machine instructions, but another intermediate code. For C# this intermediate code is called Common Intermediate Language (CIL, or just IL). Most Portable Executable (PE) files compiled and assembled from C#, whether .

Who generates IL code?

IL code is compiled by JIT Compiler. JIT Compiler converted IL Code into Machine Code.


2 Answers

Yes, there is a big difference between them, since :

  • (IL) which is also known as Microsoft Intermediate Language or Common Intermediate Language can be considered very similar to the Byte Code generated by the Java Language, and is what I think you are referring as IL Code in your question .

  • (ILAsm) has the instruction set same as that the native assembly language has. You can write code for ILAsm in any text editor like notepad and then can use the command line compiler (ILAsm.exe) provided by the .NET framework to compile that.

I think that IL Assembly can be considered a fully fledged .NET language(maybe an intermediate language), so when you compile ILAsm with ILAsm.exe you are producing IL in pretty much the same way(with less steps) that your C# compiler does with C# Code ...

As someone stated in the comment IL Assembly is basically a human readable version of the .NET Byte Code.

like image 79
aleroot Avatar answered Oct 05 '22 07:10

aleroot


A .NET assembly does not contain MSIL, it contains metadata and bytes that represent IL opcodes. Pure binary data, not text. Any .NET decompiler, like ildasm.exe, knows how to convert the bytes back to text. It is pretty straight-forward.

The C# compiler directly generates the binary data, there is no intermediate text format. When you write your own IL code with a text editor then you need ilasm.exe to convert it to binary. It is pretty straight-forward.

The most difficult job of generating the binary data is the metadata btw. It is excessively micro-optimized to make it as small as possible, its structure is quite convoluted. No compiler generates the bytes directly, they'll use a pre-built component to get that job done. Notable is that Roslyn had to rewrite this from scratch, big job.

like image 41
Hans Passant Avatar answered Oct 05 '22 08:10

Hans Passant