Sep 15, 2014

How a .EXE file is created

How the program is converted to machine code? What are the steps involved in it?

                        First of all, The code has to be written in any text editor and save the file with an extension of ".c" for c program and ".cpp" for the C++ programs. The name of the file can be anything (it doesn't matter), but the file extension is required. Now the program is ready to convert it into a language that machine can understand (also for the compiler to execute).

Generally in any compiler,the process involves in 3 steps:

1.Preprocessing
2.Compiling
3.Linking

Preprocessing :
                     First, The program is given to the preprocessor that obeys(look at) the commands which starts with "#", generally called as "Directives". It will add the extra code that is required for the directives to execute. It like a editor that add the things to the program and make the modifications. Infact the preprocessor is integrated with the compiler, so we probably even notice it at work.
Compiling :
                  Now the modified program goes to the compiler and it converts into the machine instructions called "ObjectCode". After compiling, the object file is created (.obj file). The program is not ready to run yet.


Linking :                
                 Then after, Linker combines the object code produced by the compiler to yield the complete executable program with an extra additional code added. The extra code that was added here includes the addition of library functions like printf etc. Finally after this, an executable file is created, that is ready to run the program. Probably this linking step is automated by the compiler
                The commands necessary to compile and link are vary for the one operating systems to another.






Filed under  |