E
E
Eugene2019-03-18 17:01:25
.NET
Eugene, 2019-03-18 17:01:25

Who is the code derived from CIL (.net bytecode) for?

By compiling the source code in a .net-compatible language, we get CIL, which is subsequently translated by the virtual machine into, so to speak, the "final" code designed for a specific platform.
Usually you can find a wording like "compiled by a JIT compiler to machine code."
However, is it so right in the engine room?
After all, "machine code" means instructions that the processor can execute directly, without any additional transformations from various kinds of translators. If you open the Mono wiki page, in the first paragraph you can see for which operating systems there are implementations of mono and which processor architectures are supported. That is, you can write in Mono from under Windows, Macos, Linux, and the program you wrote will work on all OS from the list by reference (namely, Windows, Linux, BSD (FreeBSD, OpenBSD, NetBSD), Solaris, Mac OS X , Apple iOS, Wii).
But the operating system itself may not work with any processor architecture.
What I'm leading to is: if CIL is really compiled into machine code, which goes directly to the processor for execution, then why specify a list of target operating systems?
Maybe then CIL is still compiled into code for the operating system, which is already engaged in its final translation into machine code for the processor?
After all, even if we recall the book "Computer Architecture" by Tanenbaum, then there the level of machine instructions is at the very bottom, and above it there are several other levels, in particular, level 3 of the operating system

(scheme)
5c8fa0e71ba70845437399.jpeg

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Saboteur, 2019-03-18
@tw1ggyz

An executable is not a direct set of instructions. It can have a special structure - .com, exe, Linux and Unix binaries are different - CIL is compiled into machine code, but as a result, not just command bytecode is created, but a binary of a certain format that the operating system can work with - machine code must somehow be loaded into memory, perhaps not even all but in parts, the entry point must be reported to the processor, and so on.
Now there are practically no linear programs that are written in such a way that they are executed in a mono-environment - everything is written based on multitasking OS.
Thus, in the CLI, ordinary machine code that is executed by the processor, but which contains certain bookmarks, calls to operating system functions in order for this code to work successfully in a certain OS, so that it does not grab 100% of the CPU for empty cycles, and so on .
This does not mean that there is non-machine code, it means that the machine code is written to work in certain conditions and contains certain calls.

#
#, 2019-03-18
@mindtester

well-formulated question, contains at least half of the answer (c)
here so..
believe it or not, but the minimum answer is something like this - the correct format of the ps executable file yes yes, as noted by Saboteur , and the correct calls to the OS, too .. or even in the first place .. .. um .. for CIL .. the same Mono, check it out for yourself! ))

A
Alexander, 2019-03-18
@alexr64

Maybe then CIL is still compiled into code for the operating system, which is already engaged in its final translation into machine code for the processor?

There is no such concept код для операционной системы. The operating system is exactly the same program (in reality, a set of programs) like all the others.
if CIL is really compiled into machine code that goes directly to the processor for execution, then why specify a list of target operating systems?
CIL is translated into machine code by runtime (for example, mono) at the moment immediately before execution. And if the runtime cannot work on a certain OS, then CIL will not work there either.
Thus, when designing a program, you need to know which operating systems have a working runtime. Also, if you are accessing OS services (implicitly through the .net wrappers provided by the BCL, or explicitly through DllImport), you need to know what OS your application will be running on in order to take OS capabilities into account.

S
Satangelus, 2019-03-18
@Satangelus

The article provided by the link explains in detail what and how under the hood of the net framework. There you will find the answer to your question.
https://habr.com/en/post/90426/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question