0% found this document useful (0 votes)
61 views3 pages

Object Code Forms in Compiler Design

The document discusses three major forms of object code generated during the final phase of compilation: Absolute Machine Code, Relocatable Object Code, and Assembly Language Code. Each form has distinct characteristics, advantages, and limitations, influencing their use in different programming contexts. The choice of object code form impacts performance, modularity, and development complexity, with modern compilers typically producing relocatable or assembly code for further processing.

Uploaded by

bebamop569
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

Object Code Forms in Compiler Design

The document discusses three major forms of object code generated during the final phase of compilation: Absolute Machine Code, Relocatable Object Code, and Assembly Language Code. Each form has distinct characteristics, advantages, and limitations, influencing their use in different programming contexts. The choice of object code form impacts performance, modularity, and development complexity, with modern compilers typically producing relocatable or assembly code for further processing.

Uploaded by

bebamop569
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

Common questions

Powered by AI

The linker plays a critical role in managing both relocatable and assembly code but in distinct ways. For relocatable code, the linker resolves symbolic references and relocation information, enabling the program to be executed in any memory space. This capability supports modular development and efficient memory management by linking various separately compiled modules. In contrast, when dealing with assembly code, the linker's role is mainly to organize object files produced after the assembly process, resolving symbol references at the machine instruction level. Both processes highlight the linker’s essential contribution to transforming these codes into a cohesive executable .

Absolute machine code, despite its limitations, is more beneficial in scenarios involving small systems or educational environments where simplicity and immediate execution are prioritized. Its direct execution capability with no need for linking makes it ideal for educational tools that require straightforward examples, such as WATFIV and PL/C. Additionally, for environments where programs do not need to be modular or shared and memory resources are limited, the simplicity of absolute machine code can suffice without the overhead of relocation or assembly, offering a practical solution .

Symbolic references and relocation information in relocatable object code facilitate its execution flexibility by allowing the program’s code and data segments to be placed at any memory location. During the linking process, symbolic references are resolved to specific memory addresses, enabling the code to be relocated without altering the original module design or function call interface. This capability is particularly advantageous in modular system architectures, as it allows for efficient updates and integration of independently compiled modules, significantly enhancing the manageability and scalability of large software systems .

Absolute machine code has the characteristic of being directly executable by the processor, with instructions set at fixed memory addresses, which allows for immediate execution without additional linking or relocation. This simplicity makes it easier to implement in simple compilers and is beneficial for small systems or educational tools like WATFIV and PL/C. However, its major limitation is the lack of flexibility as every program must be loaded at the same memory address, which hinders the ability to support modular programming or libraries, rendering it unsuitable for multi-program environments. This makes absolute machine code less viable for complex, modern software development requiring modularity and reuse .

The choice of object code form profoundly influences compilation and linking strategies. Relocatable code is favored in modular, large-scale software development because it enables flexibility in memory management and reuse of code modules, which is crucial in modern applications. It allows developers to compile code modules separately and link them during the build process, helping manage resources efficiently. Conversely, assembly code is chosen when low-level control is essential, such as in embedded systems, because it provides visibility into hardware operations and optimizations. The choice between these forms is dictated by the trade-offs between development complexity, execution speed, and flexibility, calling for strategic planning .

The additional assembly step required for assembly language code impacts both efficiency and system portability. From an efficiency perspective, this step introduces a delay between code writing and execution, requiring an extra conversion phase before generating the executable binary, which can extend development cycles. Regarding portability, assembly language's hardware-specific nature limits its direct application across varying platforms, necessitating platform-specific adjustments or rewriting of the assembly code. While providing precise control and optimization opportunities, these implications can hinder rapid development and deployment across multiple environments .

Relocatable object code enhances modular and large program development by allowing programs to be placed anywhere in memory during load time. This is achieved through symbolic references and relocation information contained within the code, which supports the separate compilation of modules and enables late binding during linking. A linker is crucial in this process as it resolves these symbolic addresses and references, organizing the code into an executable format. This linkage reduces recompilation overhead when only parts of the software need updating, thereby optimizing development efficiency and flexibility .

In performance-critical applications, choosing between compiling to assembly code or directly to machine code involves several considerations. Compiling to assembly code allows for human-readable insights and optimizations, enabling fine-tuning of performance-critical operations. It provides low-level control over hardware functionalities, essential for specific system-level constraints and custom instructions. However, it involves an additional assembly step, increasing complexity. Directly compiling to machine code can maximize execution speed and simplicity, reducing time to binary execution at the cost of flexibility. The choice should balance the need for low-level optimizations against project complexity and efficiency .

Assembly language code is advantageous in system-level or embedded development due to its readability, which facilitates easier debugging and optimization by programmers. It supports macros and symbolic labels, providing detailed visibility into low-level operations and the ability to insert special machine instructions not exposed in high-level languages. These capabilities are crucial for performance-critical and hardware-near applications. However, the trade-offs include the need for an additional assembly step to convert the code into machine-executable binary, and its lower portability compared to high-level languages, which can complicate cross-platform development .

Using absolute machine code in a large-scale software development process would present significant challenges. One primary issue is its lack of flexibility regarding memory address allocation since absolute machine code contains fixed memory addresses, hindering efficient memory management and allocation across different modules. This rigidity would severely limit the ability to use shared libraries, complicating modular programming approaches and increasing difficulty in maintaining and updating code. Additionally, the necessity for recompilation of entire programs when updates are made, due to fixed addresses, would dramatically increase overheads, contrary to the seamless updates possible with relocatable code .

You might also like