0% found this document useful (0 votes)
9 views4 pages

Understanding Object Code in Compilers

Uploaded by

vijayaselvi2020
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)
9 views4 pages

Understanding Object Code in Compilers

Uploaded by

vijayaselvi2020
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

UNIT V

Introduction of Object Code in Compiler Design


 Object code is the intermediate code that is generated by the compiler after the syntax analysis,
semantic analysis, and optimization stages.

 Object code is essentially the machine-readable version of the source code, which can be executed
directly by the computer’s CPU.
 Object code is typically stored in a binary file format, which is specific to the target
architecture and operating system.
 The object code file contains both the executable code and data, as well as information
about the program’s symbols and their memory locations.

Object code is generated by the compiler in multiple steps.

 First, the source code is transformed into an intermediate representation, such as an


abstract syntax tree or a three-address code.
 Then, the intermediate code is optimized to improve the efficiency and speed of the
final executable code.
 Finally, the optimized intermediate code is translated into the target architecture’s
machine code, using the appropriate instruction set and addressing modes.

 Object code can be linked with other object files to produce a complete executable
program.

 The linking process involves resolving any unresolved external references, such as
function calls or global variables, and generating a final executable file that can be run
on the target system.

o Object code is the machine-readable code that is generated by the compiler, and it serves as
an intermediate step between the source code and the final executable code.
o Object code files are specific to the target architecture and operating system and are typically
stored in a binary file format.

 The compiler is actually combined inside the assembler along with loader and linker.
 So all the module kept together in the compiler software itself.
 Once you call the compiler, then your object code is going to present in Hard-disk.
 This object code contains various part.

 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.
 Text segment – It is nothing but the set of instruction.
 Data segment – Data segment will contain whatever data you have used.
For example, you might have used something constraint, then that going
to be present in the data segment.
 Relocation Information – Whenever you try to write a program, we generally use symbol
to specify anything.

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

 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.

 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 Reallocation.

Features :

Machine-readable format: Object code is in a format that can be executed directly by the
processor without the need for further translation.
Architecture-specific: Object code is specific to a particular processor architecture, so it
must be recompiled for other architectures.
Linking: Object code can be linked together with other object files and libraries to create a
complete executable program.
Debugging information: Object code can include debugging information, such as line
numbers and variable names, to aid in debugging the program.
Relocation information: Object code includes information about the addresses of symbols in
the code, allowing the linker to adjust the addresses when the code is linked with other code.
Code optimization: Object code can be optimized by the compiler to improve performance,
reduce code size, or both.
Assembly code: Object code can be disassembled into assembly code, which can be useful
for understanding how the program works or for reverse engineering.

Advantages:

1. Efficiency: Object code is optimized for the specific target platform, which can result in more
efficient code than would be possible with a high-level language.
2. Portability: Object code is typically platform-specific, but it can still be portable across different
systems that use the same platform.
3. Debugging: Object code can be easier to debug than source code, as it provides a low-level view
of the program’s execution.
4. Protection: Object code can be protected through the use of obfuscation techniques, making it
harder for others to reverse engineer the code or steal intellectual property.
5. Security: Object code is more secure than source code because it is not readable by humans,
making it more difficult for attackers to reverse engineer the code.
6. Interoperability: Object code can be easily linked with other object files to create a complete
executable program.
Disadvantages:

1. Platform-specific: Object code is specific to a particular platform, which means that it may not be
compatible with other systems.
2. Limited readability: Object code is a low-level language that is harder to read and understand
than source code.
3. Limited control: Object code is generated by the compiler, and developers have limited control
over the resulting code.
4. Compatibility issues: Object code can sometimes be incompatible with other components of the
system, which can cause errors or performance issues.
5. Code size: Object code is typically larger than source code because it contains additional
information, such as symbols and relocation information.

You might also like