The Wayback Machine - https://web.archive.org/web/20240927180615/https://www.geeksforgeeks.org/introduction-of-object-code-in-compiler-design/
Open In App

Introduction of Object Code in Compiler Design

Last Updated : 12 May, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Let assume that, you have a c program, then you give the C program to compiler and compiler will produce the output in assembly code. Now, that assembly language code will give to the assembler and assembler is going to produce you some code. That is known as Object Code. 

In the context of 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.

  1. 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.
  2. 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.
  3. 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.

In summary, 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. Object code files are specific to the target architecture and operating system and are typically stored in a binary file format.

compilation But, when you compile a program, then you are not going to use both compiler and assembler. You just take the program and give it to the compiler and compiler will give you the directly executable code. The compiler is actually combined inside the assembler along with loader and linker.So all the module kept together in the compiler software itself. So when you calling gcc, you are actually not just calling the compiler, you are calling the compiler, then assembler, then linker and loader. Once you call the compiler, then your object code is going to present in Hard-disk. This object code contains various part – compilation2

  • 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. It is nothing but like an index, like you have a textbook, there an index page will contain at what page number each topic present. Similarly, the header will tell you, what are the palaces at which each information is present. So that later for other software it will be useful to directly go into those segment.
  • 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,…. compilation3 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. 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 Reallocation. compilation4 The original address is known as Relocatable address and the final address which we get after loading the program into main memory is known as the Absolute address.

Symbol table –

  • It contains every symbol that you have in your program. for example, int a, b, c then, a, b, c are the symbol.it will show what are the variables that your program contains.

 

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. This allows developers to write code once and compile it for multiple target systems.
  3. Debugging: Object code can be easier to debug than source code, as it provides a low-level view of the program’s execution. Developers can use object code to trace the execution of the program and identify errors or issues that may be present.
  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. This can limit the portability of the code and make it harder to deploy across multiple systems.
  2. Limited readability: Object code is a low-level language that is harder to read and understand than source code. This can make it more difficult for developers to maintain and debug the code.
  3. Limited control: Object code is generated by the compiler, and developers have limited control over the resulting code. This can limit the ability to optimize the code or tailor it to specific requirements.
  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.
  6. Licensing: Object code may be subject to licensing restrictions that limit its use and distribution.

Debugging information –

  • It will help to find how a variable keeps on changing. GATE CS Corner Questions Practicing the following questions will help you test your knowledge. All questions have been asked in GATE in previous years or in GATE Mock Tests. It is highly recommended that you practice them. 1. GATE-CS-2001 | Question 17

Previous Article
Next Article

Similar Reads

Incremental Compiler in Compiler Design
Incremental Compiler is a compiler that generates code for a statement, or group of statements, which is independent of the code generated for other statements. Examples : C/C++ GNU Compiler, Java eclipse platform, etc. The Incremental Compiler is such a compilation scheme in which only modified source text gets recompiled and merged with previousl
5 min read
Advantages of Multipass Compiler Over Single Pass Compiler
Programmers, write computer programs that make certain tasks easier for users. This program code is written in High-Level Programming languages like C, C++, etc. Computer device doesn't understand this language or the program written by a programmer, so the translator that translates the High-Level Program code into Machine Readable Instructions is
6 min read
Difference between Native compiler and Cross compiler
1. Native Compiler : Native compiler are compilers that generates code for the same Platform on which it runs. It converts high language into computer's native language. For example, Turbo C or GCC compiler. if a compiler runs on a Windows machine and produces executable code for Windows, then it is a native compiler. Native compilers are widely us
6 min read
Compiler Design | Detection of a Loop in Three Address Code
Prerequisite - Three address code in Compiler Loop optimization is the phase after the Intermediate Code Generation. The main intention of this phase is to reduce the number of lines in a program. In any program majority of the time is spent actually inside the loop for an iterative program. In the case of the recursive program a block will be ther
3 min read
Target Code Generation in Compiler Design
Target code generation is the final Phase of Compiler. Input : Optimized Intermediate Representation. Output : Target Code. Task Performed : Register allocation methods and optimization, assembly level code. Method : Three popular strategies for register allocation and optimization. Implementation : Algorithms. Target code generation deals with ass
2 min read
Machine Independent Code optimization in Compiler Design
Machine Independent code optimization tries to make the intermediate code more efficient by transforming a section of code that doesn't involve hardware components like CPU registers or any absolute memory location. Generally, it optimizes code by eliminating redundancies, reducing the number of lines in code, eliminating useless code or reducing t
7 min read
Common Subexpression Elimination - Code optimization Technique in Compiler Design
Code Optimization Technique is an approach to enhance the performance of the code by either eliminating or rearranging the code lines. Code Optimization techniques are as follows: Compile-time evaluation Common Sub-expression elimination Dead code elimination Code movement Strength reductionCommon Sub-expression Elimination:The expression or sub-ex
2 min read
Global Code Scheduling in Compiler Design
In the fifth phase of compiler design, code optimization is performed. There are various code optimization techniques. But the order of execution of code in a computer program also matters in code optimization. Global Code Scheduling in compiler design is the process that is performed to rearrange the order of execution of code which improves perfo
7 min read
Intermediate Code Generation in Compiler Design
In the analysis-synthesis model of a compiler, the front end of a compiler translates a source program into an independent intermediate code, then the back end of the compiler uses this intermediate code to generate the target code (which can be understood by the machine). The benefits of using machine-independent intermediate code are: Because of
5 min read
Code Optimization in Compiler Design
Code optimization is a crucial phase in compiler design aimed at enhancing the performance and efficiency of the executable code. By improving the quality of the generated machine code optimizations can reduce execution time, minimize resource usage, and improve overall system performance. This process involves the various techniques and strategies
9 min read
Introduction of Compiler Design
Compiler design is, in fact, the translation of the source code written in a high-order programming language into the machine language that the computer will execute. It comprises a number of phases where the code is pre-processed, and parsed, its semantics or meaning are checked, and optimized, and then the final executable code is generated. What
11 min read
Introduction to Syntax Analysis in Compiler Design
Syntax analysis, often known as parsing, is an important step in the compilation process. Following lexical analysis (which divides the input into tokens), syntax analysis ensures that these tokens are arranged according to with the programming language's grammar. This process helps in detecting and reporting errors, ensuring the source code adhere
8 min read
Difference Between Source Code and Object Code
Anyone needs to have the background knowledge that is required when studying computer programming, especially that of the difference between source code and object code. Such terms are used when describing the process of developing software, compiling it, and its execution. In this article, you will learn what source code and object code are as wel
6 min read
Three address code in Compiler
TAC is an intermediate representation of three-address code utilized by compilers to ease the process of code generation. Complex expressions are, therefore, decomposed into simple steps comprising, at most, three addresses: two operands and one result using this code. The results from TAC are always stored in the temporary variables that a compile
6 min read
Compiler Design - GATE CSE Previous Year Questions
Solving GATE Previous Year's Questions (PYQs) not only clears the concepts but also helps to gain flexibility, speed, accuracy, and understanding of the level of questions generally asked in the GATE exam, and that eventually helps you to gain good marks in the examination. Previous Year Questions help a candidate practice and revise for GATE, whic
4 min read
Syntax Directed Translation in Compiler Design
Parser uses a CFG(Context-free-Grammar) to validate the input string and produce output for the next phase of the compiler. Output could be either a parse tree or an abstract syntax tree. Now to interleave semantic analysis with the syntax analysis phase of the compiler, we use Syntax Directed Translation. Conceptually, with both syntax-directed de
5 min read
Peephole Optimization in Compiler Design
Peephole optimization is a type of code Optimization performed on a small part of the code. It is performed on a very small set of instructions in a segment of code. The small set of instructions or small part of code on which peephole optimization is performed is known as peephole or window. It basically works on the theory of replacement in which
2 min read
Error Handling in Compiler Design
The tasks of the Error Handling process are to detect each error, report it to the user, and then make some recovery strategy and implement them to handle the error. During this whole process processing time of the program should not be slow. Functions of Error Handler: Error DetectionError ReportError RecoveryError handler=Error Detection+Error Re
7 min read
Synthesis Phase in Compiler Design
Pre-requisites: Phases of a Compiler The synthesis phase, also known as the code generation or code optimization phase, is the final step of a compiler. It takes the intermediate code generated by the front end of the compiler and converts it into machine code or assembly code, which can be executed by a computer. The intermediate code can be in th
4 min read
Labeling Algorithm in Compiler Design
Labeling algorithm is used by compiler during code generation phase. Basically, this algorithm is used to find out how many registers will be required by a program to complete its execution. Labeling algorithm works in bottom-up fashion. We will start labeling firstly child nodes and then interior nodes. Rules of labeling algorithm are: Traverse th
3 min read
Transition diagram for Identifiers in Compiler Design
Transition diagram is a special kind of flowchart for language analysis. In transition diagram the boxes of flowchart are drawn as circle and called as states. States are connected by arrows called as edges. The label or weight on edge indicates the input character that can appear after that state. Transition diagram of identifier is given below: T
4 min read
Input Buffering in Compiler Design
The lexical analyzer scans the input from left to right one character at a time. It uses two pointers begin ptr(bp) and forward ptr(fp) to keep track of the pointer of the input scanned. Input buffering is an important concept in compiler design that refers to the way in which the compiler reads input from the source code. In many cases, the compil
5 min read
Bootstrapping in Compiler Design
Bootstrapping is a process in which simple language is used to translate more complicated program which in turn may handle for more complicated program. This complicated program can further handle even more complicated program and so on. Writing a compiler for any high level language is a complicated process. It takes lot of time to write a compile
4 min read
Loop Optimization in Compiler Design
Loop Optimization is the process of increasing execution speed and reducing the overheads associated with loops. It plays an important role in improving cache performance and making effective use of parallel processing capabilities. Most execution time of a scientific program is spent on loops. Loop Optimization is a machine independent optimizatio
4 min read
Semantic Analysis in Compiler Design
Semantic Analysis is the third phase of Compiler. Semantic Analysis makes sure that declarations and statements of program are semantically correct. It is a collection of procedures which is called by parser as and when required by grammar. Both syntax tree of previous phase and symbol table are used to check the consistency of the given code. Type
2 min read
Error Recovery Strategies in Compiler Design
The error may occur at various levels of compilation, so error handling is important for the correct execution of code. There are mainly five error recovery strategies, which are as follows: Panic modePhrase level recoveryError productionGlobal correctionSymbol tablePanic Mode:This strategy is used by most parsing methods. In this method of discove
4 min read
BNF Notation in Compiler Design
BNF stands for Backus Naur Form notation. It is a formal method for describing the syntax of programming language which is understood as Backus Naur Formas introduced by John Bakus and Peter Naur in 1960. BNF and CFG (Context Free Grammar) were nearly identical. BNF may be a meta-language (a language that cannot describe another language) for prima
3 min read
Register Allocation Algorithms in Compiler Design
Register allocation is an important method in the final phase of the compiler . Registers are faster to access than cache memory . Registers are available in small size up to few hundred Kb .Thus it is necessary to use minimum number of registers for variable allocation . There are three popular Register allocation algorithms . Naive Register Alloc
5 min read
Language Processing System in Compiler Design
The computer is an intelligent combination of software and hardware. Hardware is simply a piece of mechanical equipment and its functions are being compiled by the relevant software. The hardware considers instructions as electronic charge, which is equivalent to the binary language in software programming. The binary language has only 0s and 1s. T
4 min read
Constant Propagation in Compiler Design
Constant Propagation is one of the local code optimization technique in Compiler Design. It can be defined as the process of replacing the constant value of variables in the expression. In simpler words, we can say that if some value is assigned a known constant, than we can simply replace the that value by constant. Constants assigned to a variabl
3 min read
Article Tags :