Ever wondered what happens to the program when you hit the enter button on your keyboard ? What is meant by compilation of a program ? This blog explains varies steps or processes involved in the conversion of a C code to the execution of the executable code.
The first process which our Hello_World.c encounters is preprocessing where the preprocessor replaces #define (macro), #include (files), conditional codes like #if and #endif, and other directives like #pragma by their respective values & source codes in source files.
Converts Hello_World.c to Hello_World.i
The compiler can be divided into two parts : the front-end and the back-end. The front-end can be considered as the analysis phase where the compiler checks for errors (syntax and semantics of the program). This is done by lexical, syntax and semantic analysis. The back-end part can be considered as synthesis phase where the compiler generates the assembly code from the analysed code and it also involves code optimisation. In short the compiler compiles the expanded source code to assembly source code.
Converts Hello_World.i to Hello_World.s
Assembler is a program that converts assembly source code to object code. Assembly language instructions usually consist of an opcode mnemonic followed by a list of data, arguments or parameters. The assembler may also perform some optimisations.
Converts Hello_World.s to Hello_World.o
This is a program that converts object code to an executable code and combines all object codes together. All the files might have been compiled by separate assemblers. The major task of a linker is to search and locate referenced module/routines in a program and to determine the memory location where these codes will be loaded, making the program instruction to have absolute references.
Converts Hello_World.o to Hello_World.exe
Loader is a part of operating system and is responsible for loading executable files into memory and execute them. It calculates the size of a program (instructions and data) and creates memory space for it. It initialises various registers to initiate execution.
For lazy people who cant go through the entire article refer to the below image. It pretty much summarises the article.