Journey of the “Hello world” program

Kausthub TM
Mar 4 · 2 min read

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.

Hello_World.c

Preprocessor directives

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

Compiler

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

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

Linker

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

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.

Summary :

For lazy people who cant go through the entire article refer to the below image. It pretty much summarises the article.

Processes involved for a C program.

Nerd For Tech

From Confusion to Clarification

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/. Don’t forget to check out Ask-NFT, a mentorship ecosystem we’ve started

Kausthub TM

Written by

NITK - IT undergrad

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/. Don’t forget to check out Ask-NFT, a mentorship ecosystem we’ve started

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store