xdevel2000
xdevel2000

Reputation: 21444

IL code vs IL assembly: is there a difference?

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?

Upvotes: 9

Views: 6368

Answers (2)

Hans Passant
Hans Passant

Reputation: 942197

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.

Upvotes: 3

aleroot
aleroot

Reputation: 72676

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.

Upvotes: 8

Related Questions