Search code examples
assemblycompilationcpu-architecture

Are all programs eventually converted to assembly instructions?


From what I understand processor circuitry varies greatly from chip to chip and therefore may require different low level instructions to execute the same high level code. Are all programs eventually converted to assembly language before becoming raw machine code or is this step no longer necessary?

If so, at what point does the processor begin to execute its own unique set of instructions? This is the lowest level of code, so is it at this point that the program instructions are executed by the processor, bit by bit?

Finally, do all architectures have/need an assembly language?


Solution

  • Assembly language is, so to say, a human-readable form of expressing the instructions a processor executes (which are binary data and very hard to manage by a human). So, if the machine instructions are not generated by a human, using assembly step is not necessary, though it sometimes does happen for convenience. If a program is compiled from a language such as C++, the compiler may generate machine code directly, without going through the intermediate stage of assembly code. Still, many compilers provide an option of generating assembly code in order to make it easier for a human to inspect what gets generated.

    Many modern languages, for example Java and C# are compiled into so-called bytecode. This is code that the CPU does not execute directly, but rather an intermediate form, which may get compiled to machine code just-in-time (JIT-ted) when the program is executed. In such a case, CPU-dependent machine code gets generated but usually without going through human-readable assembly code.