Social Icons

Tuesday, December 17, 2013




Basically assembler is a tool which will take part in the compilation process. It will take the output generated by the compiler and convert it into machine instructions which the computer will understand. When I am referring the terms compiler and compilation, please be aware that both are different. 
Compiler is a tool and compilation is a process of converting the high level language written source code into machine understandable instructions.
                              So, we have already seen how the stages of compilation. The assembler will be invoke in the third stage of the compilation process. The output generated by the compiler which will have an extension ' .s ' i.e filename.s will be taken as input by the assembler and will be converted into machine readable instructions. The file generated is called  as the object file.


Now we will see how the assembler will work. I am assuming that anyone who is reading this article has read the previous articles. If any confusion arises please follow my old articles. I am covering each and every topic very systematically.
                                          So coming to the assembler we have already seen what the compiler will generate as an output. The output generated by the compiler is used as the input by the assembler tool.

We are going to do a step by step compilation of a C program. In my last two posts on understanding the preprocessor and the compiler I used a C program "add.c". If you have not read those two previous posts of mine I am afraid some of you might feel it difficult to understand this article. Well I am assuming you have already read those two previous posts. So after the compilation we get the output file add.s which will be used as the input file for the assembler.

  Here I did an ls command to display the files I have currently in my directory. We got the output generated by the compiler i.e the tool called cc1 which generated the add.s which will be input to the assembler.


We have previously invoked the pre-processor and the compiler independently. To invoke the assembler the command is  gcc  -c  add.s  -o  add.o
 The output generated will be an object file called add.o . This file will contain the machine instructions which will be used by the linker.

The path followed by the assembler is similar to that of the pre-processor and the compiler. I am going to execute the above command with a " -v " flag which will give the verbose output. The path followed will be similar to that of the pre-processor and the compiler except for the tool i.e assembler uses a tool called " as " where as the compiler and pre-processor will use a tool called the cc1.

gcc  -c -v  add.s  -o add.o

The above screen shot will help you locate the tool " as ". Rest of the process followed by the assembler is similar to that of the pre-processor and the compiler. Please refer the previous articles for more clarity.

No comments:

Post a Comment