do you know how your code
int f(){
return 42;
}
turns into
mov eax, 42 ret
and then into
B8 2A 00 00 00 C3
this?
<aside> š”
Hereās the short thing:
source code ā something happens, Intermediate code forms ā something happens again, Machine code is formed.
Weāll clear the āsomethingā in this article.
</aside>
Life would be very simple if we humans could write 1s and 0s and directly give machine itās prefered machine code. But since we donāt have 1000 hands per person and the outputs that weāre expecting out of computers have evolved to complexities unimaginable, we need another simpler way to talk to the machines. And that is why we have different programming languages and their compilation processes.
There are compiled languages and interpreted languages divided on the basis of when the code is executed.
Compiled languages are programming languages that are converted into machine code by the compiler and only then, is there an executable file.
Interpreted languages are not converted into compiled code, rather the source code is directly executed line-by-line by the interpretor.
CAVEAT: most of the lanugages today use a mixture of the two ideas. Ex. Initially, the JVM interprets the Java bytecode produced by the Java compiler, executing it instruction by instruction until it identifies frequently executed (āhotā) code paths, which are then compiled into native machine code by the JIT compiler for faster execution.