Assembling

In this tutorial, we will learn how assembling is performed by the assembler in details.


The process

Similar to a compiler, an assembler also transforms code from one form to another.

The program execution process

Based on the diagram provided, the compiler takes expanded source code and produces assembly code. Then, the assembler takes the assembly code and generates object code, which is also known as machine code. So, we can conclude that the assembler is a software program created to convert assembly code into the object code.

To generate object code solely from assembly code, you need to enter the following command:

gcc -C add.s -o add.o

In the above command

  1. -C is needed to assemble the code and stop further processing.
  2. add.o is the name of the object file.

When we open the object file in Code::Blocks, we will see some strange and unreadable text. This is because the object file contains machine-level instructions that are not meant to be human-readable.


Conclusion

So far, only the existing code has been converted to machine code. However, the call to the printf() function has not been resolved yet. The preprocessor has added the necessary declarations, and the compiler assumes that the definition of this function exists somewhere and will be taken care of later. This task is handled by the linker in the linking phase, which we will learn about in the next tutorial.



Leave a comment

Leave a comment

Your email address will not be published. Required fields are marked *

Thank you for choosing to leave a comment. Please be aware that all comments are moderated in accordance with our policy. For more information, please review our comments policy. Rest assured that your email address will not be shared with anyone. Kindly refrain from using keywords in your comment. Let’s maintain a respectful atmosphere and engage in meaningful conversations.