Object Code Forms in Compilation
In the final phase of compilation, the compiler translates the intermediate representation of a program into an
object code that can be understood and executed by the target machine. The form of the object code
generated depends on the target platform, development workflow, and the need for flexibility, efficiency, and
modularity. The three major forms of object code are:
1. Absolute Machine Code
2. Relocatable Object Code
3. Assembly Language Code
Each of these object code forms has unique characteristics, use cases, and trade-offs.
1. Absolute Machine Code
Absolute machine code is the raw binary format directly executable by the processor. It contains instructions
with fixed memory addresses.
- Characteristics:
- Immediate execution: No need for linking or relocation.
- Simplicity: Easier to implement for simple compilers.
- Used in small systems or educational tools like WATFIV, PL/C.
- Limitations:
- No flexibility: Every program must be loaded at the same memory address.
- Difficult to support modular programming or libraries.
- Not reusable or shareable in multi-program environments.
Example: Absolute Machine Code
Memory Address | Instruction
0x0000 | LOAD A
0x0001 | ADD B
0x0002 | STORE C
0x0003 | HALT
Object Code Forms in Compilation
2. Relocatable Object Code
Relocatable object code allows a program to be placed anywhere in memory at load time. It supports
separate compilation of modules and late binding during linking.
- Characteristics:
- Contains symbolic references and relocation information.
- Facilitates modular and large program development.
- Supports reuse of libraries and system calls.
- Advantages:
- Enhances memory management flexibility.
- Reduces recompilation overhead when only some modules change.
- Requirement:
- Needs a linker to resolve addresses and produce executable code.
Example: Relocatable Code Snippet
Symbol Table:
START -> Offset 0x0040
Instruction: JMP START ; Linker resolves actual address
3. Assembly Language Code
Assembly code is a human-readable representation of machine instructions. It must be assembled into
machine code by an assembler.
- Characteristics:
- Easier for programmers to read, debug, and optimize.
- Supports macros and symbolic labels.
- Often used in system-level or embedded development.
Object Code Forms in Compilation
- Advantages:
- Provides visibility into low-level operations.
- Allows insertion of special machine instructions not exposed in high-level languages.
- Drawbacks:
- Requires an additional assembly step.
- Less portable compared to high-level code.
Example: Assembly Code
MOV AX, 0010h
ADD AX, BX
MOV [RESULT], AX
Comparison of Object Code Forms
| Code Form | Readable | Direct Execution | Linking Required | Use Case |
|------------------------|----------|------------------|-------------------|----------------------------------|
| Absolute Machine Code | No | Yes | No | Educational tools, small systems |
| Relocatable Code | No | No | Yes | Modular, large systems |
| Assembly Code | Yes | No | Yes (after ASM) | System-level, embedded coding |
Conclusion
Choosing the right form of object code is essential for balancing performance, modularity, and development
complexity. Absolute code is fast and simple, but inflexible. Relocatable code is ideal for complex and
modular software development. Assembly code offers low-level control and is crucial in performance-critical
or hardware-near applications.
Modern compilers often produce relocatable code or assembly code, which is then processed further by
linkers and loaders to generate final executables.