Object Code in Compiler Design (original) (raw)

Last Updated : 24 Apr, 2026

Object Code is the machine-level code produced by a compiler after translating the source program. It is a low-level binary representation that the computer can understand but is not yet directly executable.

For example, if a programmer writes a program in C language, the compiler first translates it into assembly language, and then the assembler converts the assembly code into object code. This object code is later combined with other object files and libraries by a linker to produce the final executable program.

Thus, object code acts as an intermediate step between compilation and execution.

OBJECT-CODE-2

Object code creation

Steps Involved in Compilation

The process of generating object code involves several stages:

  1. **Source Code: The programmer writes the program in a high-level programming language (like C, Java, Python, etc.).
  2. **Lexical Analysis: The compiler performs lexical analysis to break the source code into tokens (keywords, operators, identifiers, etc.).
  3. **Syntax and Semantic Analysis: Compiler checks the structure (syntax) and meaning (semantics) of the code, ensuring that it follows the rules of the language and is logically correct.
  4. **Intermediate Code Generation: The compiler may create an intermediate code that is not machine-specific, providing a way to optimize or analyze the program further. This is often a platform-independent representation.
  5. **Code Generation (Object Code): Finally, the compiler translates the intermediate code into object code, which is machine-level code specific to the target machine architecture but still not fully executable.

**Structure of Object Code

Object code is a binary file that contains machine instructions, but it's not directly executable yet. The object code is typically in a format that can be understood by the computer’s linker (a separate tool that helps to create an executable file). The main elements of object code include:

OBJECT-CODE

Object Code Structure

**Header : The header will say what are the various parts present in this object code and then point that parts. So header will say where the text segment is going to start and a pointer to it and where the data segment going to start and it say where the relocation information and symbol information there.

**Text segment : This section contains the actual machine instructions generated by the compiler.

**Data Sections: Object code may contain sections for data (variables, constants, etc.), including initialized data and uninitialized data (commonly called ****.**data and .bss sections).

**Relocation Information: Object code may include information on how addresses should be adjusted during the linking process. It’s used to modify addresses of variables and functions when combining multiple object files into a single executable.

Let us assume you have instruction 1, instruction 2, instruction 3, instruction 4,....

Now if you say somewhere Goto L4 (Even if you don't write Goto statement in the high-level language, the output of the compiler will write it), then that code will be converted into object code and L4 will be replaced by Goto 4.

compilation3

Now Goto 4 for the level L4 is going to work fine, as long as the program is going to be loaded starting at address no 0. But in most cases, the initial part of the RAM is going to be dedicated to the operating system. Even if it is not dedicated to the operating system.

Then might be some other process that will already be running at address no 0. So, when you are going to load the program into memory, means if the program has to be loaded in the main memory, it might be loaded anywhere. Let us say 1000 is the new starting address, then all the addresses have to be changed, that is known as **Relocation.

compilation4

Relocation of addresses

**Symbol Table: The object code contains a **symbol table that keeps track of all the variables, functions, and other symbols used in the program. This table is essential for linking because it helps the linker resolve references to functions or variables that are defined elsewhere (in other object files or libraries).

**Debugging Information: Sometimes, object code also contains debugging information, allowing developers to debug the program after compilation (e.g., file names, line numbers, variable names).

Advantages

Disadvantages