Life Stages Of Any Program


Welcome back to my blog, i have kept the things with different flavours, and blogging with different technologies keep the fact that i will help most of the users world wide. I will be exploring more into windows internals but prior to that i would like to get into the basics ,i understand most of the engineers do not get a chance to really know whatz happening at the lower end of any PC.

 

I respect the documents, publications , books which explains how the computer architecture is built and the data flow, every computer is made up of several hardware and i would say combination of hardware and logic gates, every chip has trillions of gates ( logic gates ) .So for an engineer its always tough to decide the path , either electronics / computers , well if you want to really touch the core of OS you should be master of both and particularly mathematics 🙂

 

 

Finally OS ends with exe’s , dll’s , libraries, processes, threads etc.. when i learnt my first program "hello world" K&R i was curious to understand about the what happens when i click execute tab / compile tab. I wasnt keen what i typed but the latter was interesting to me.

 

 

Below program is a classic newbie pgm to start with. You get an output "hello world " after it successfully run. But every engineer should know that in order to get the output , every component of OS should work.

 

 

 

#include <stdio.h>

 

void main()

{

Printf("hello, worldn");

}

 

 

Following the process that i would encourage each one of the engineer to understand which will make them a robust programmer.

 

Stage 1 : save the program as test.c from the editor

 

stage 2 : test.c is interpreted as bits ( 0 or 1 ) and each of these bits are grouped to

              form a byte . A byte is of 8-bits. Each of these bytes represent a character

           

Stage 3 :  we follow ACSII convention / standard to represent these characters.

               ASCII standard represent each character with unique byte integer value

 

for eg the above program is represented in a file as

 

#     i     n      c     l       u      d      e      <sp>  <    s     t      d     i      o      .    h     >     n  

35   105  110   99   108   117  100   101   32      60  115  116  100  105  111  46  104  62    10  

 

Please note that after end of <stdio.h> the line is terminated by newline character "n" and this is not visible for the end users. So the above program is stored as sequential bytes and not characters.

 

Stage 4 : At the back ground this source file should be converted to appropriate machine instruction which

              then produces the output called  "exe "

 

Before programmer gets the exe , test.c will undergo different phases which are listed below

 

Preprocessor :  In this phase the preprocessor adds different programs , yes i am correct, you have added

                      stdio.h in your test.c , so during this phase preprocessor reads the contents of stdio.h and

                      adds them to the program and send the file to compiler

 

Compilation  :  Compiler accepts the output of preprocessor as input and converts the text to assembly

                      language and send the file to assembler . Will define more about compiler in my next blog

                      about lexical analysis , parsing, code generation which are building blocks of compiler.

 

Assembly     :  Assembler accepts the file from compiler and then converts the assembly instruction to

                      machine level language instructions. The assembler creates an obj file ( eg: test.o ).

                      This file is sent to linker

 

Linking         :  The main objective of linker is to link files , simple right ! , let me explain : in our program

                      we have defined printf function rather predefined function. This printf resides in precompiled

                      object file ( printf.o ) and which should be linked to our program, this is performed by linker.

                      After the linking has been done , the output we get is executable.

 

 

 test.c / test.cpp –> Preprocessor –> compiler –> assembler –> linker –> executable

 

 

Now the interesting part, every programer understands the above portion but what makes him an expert ???

When he analyzes the assembly portion of the code he understands about how the code is handled both in terms of memory and machine language.

 

Wait for more in next blog

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s