Home > Mobile >  How does the OS know which assembly language it needs to translate itself to?
How does the OS know which assembly language it needs to translate itself to?

Time:11-18

It is said that most of the OS is written in a portable computer language (usually C). This is done so that the OS can function on different CPU architectures. Naturally, the part of the OS that is not written in C (or some other high level language) will contain some compiler that will translate the OS C code into machine language. If that was the case, how does the [compiler within the] OS knows which machine language to translate the C code into?

CodePudding user response:

The OS you install is written in machine code for your particular class of computer. The developers at Microsoft (for example) already compiled the OS into x86 machine code so x86 computers could run it. They put the x86 machine code on the CD and that was installed onto your computer.

The compiler knows to make x86 machine code because Microsoft told it to. Perhaps Microsoft also made a ARM64 or SPARC version of their OS - but that's not the one you bought. If you did buy it, it wouldn't work on your computer and you'd have to return it.

  • Related