Assembling
In this tutorial, we will learn how assembling is performed by the assembler in details.
In this tutorial, we will learn how assembling is performed by the assembler in details.
Similar to a compiler, an assembler also transforms code from one form to another.
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
-C
is needed to assemble the code and stop further processing.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.
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