Click here to Skip to main content
15,868,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Im wondering how the MSIL is running without being compiled firstly ? As I know .NET uses a JIT compiler and the JIT compiler is both interpreter and compiler which runs after the program start (in run-time). So how the MSIL is getting executed ?

What I have tried:

Asking a question here in CodeProject.com
Posted
Updated 28-Jul-17 19:57pm
Comments
Richard MacCutchan 28-Jul-17 16:41pm    
You have answered your own question. It passes into the JIT compiler, which interprets and executes it.
The_Unknown_Member 28-Jul-17 17:29pm    
@Richard MacCutchan Can you also explain me how the Assembly code executes ? For example lets assume we have a program of 100 lines assembly code and when this assembly code start assembling from Assembly to a Native code is it doing it line by line or doing all at once ?
Richard MacCutchan 29-Jul-17 4:14am    
Google will find you lots of information on MSIL and JIT.

1 solution

Quote:
So how the MSIL is getting executed ?
There is a wealth of resources on t'internet which explain this: Code Execution Process[^] provides a nice overview, but Google can find you more details.
Quote:
Can you also explain me how the Assembly code executes ? For example lets assume we have a program of 100 lines assembly code and when this assembly code start assembling from Assembly to a Native code is it doing it line by line or doing all at once ?

It's never that simple.
MSIL (now called CIL, Common Intermediate Language) is effectively the assembler code, a true native assembly language program is never produced for .NET projects. If you mean real assembler code as in "native processor assembler" then it is (sort of) processed line by line to produce a complete executable file (but the line by line bit is untrue, because there are forward and backward references to consider, and assemblers are normally multipass processing as a result).
MSIL is converted to native code (i.e. binary code that can execute directly on the actual processor) by the JIT compiler on a method-by-method basis, not line by line (except it can also be completely precompiled by Ahead-of-time compilation using NGEN, but that is less common).

And the JIT is only done once: the compiled results are stored and reused.
 
Share this answer
 
Comments
The_Unknown_Member 29-Jul-17 3:24am    
"MSIL is converted to native code (i.e. binary code that can execute directly on the actual processor) by the JIT compiler on a method-by-method basis, not line by line"

And after that how the native code is executing ? Is it line by line ? Because I think if it wasn't line by line then we couldn't have Run-Time time
OriginalGriff 29-Jul-17 3:37am    
No, not line by line - processors have no idea of lines, and a single line of C# , or even CIL may be a number of machine instructions, depending on the line, and on the actual processor executing the code. Processors work in machine code instructions which are binary values the execution unit "decodes" into various operations: "move to this register", "add that register", "store in this memory address". Or even "copy the number of bytes in this register from the memory address pointed at by this register offset by that register to the memory address pointed at by the other register offset by a totally different register is the carry flag is set" in extreme cases. Execution at the processor level is always in terms of machine code, nothing else. Except ... if you take the Red Pill you find the rabbit hole goes a lot deeper than that, and the machine code is often hardware interpreted by microcode processors which pretend to actually understand the machine code. The layers can get pretty deep if you start looking for the "ultimate silicon" execution layer.

If I was you, I'd just leave that all alone for the moment, and work with the higher level abstractions of C# and CIL: it starts to get murky when you dive any deeper and you get a heck of a lot of "lies to children" on the way down. :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900