ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3149Target Language Addres…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3149

    Compiler Construction

    Progress0 / 32 done
    Topics32
    1Introduction to interpreter and compiler2Structure of a Compiler and its Phases3Lexical Analyzer and Input Buffering4Specifications and Recognitions of Tokens5Regular Expressions and Finite Automata6Transition Table and Transition Graph7Definitions of Grammars, Derivations, and Parse Trees8Ambiguity, Associativity, and Precedence of Operators9Syntax Analysis and Role of the Parser10Eliminating Ambiguity, Left Recursion, and Left Factoring11Top-Down Parsing and Recursive-Descent Parsing12First and Follow Sets13LL(1) Grammars and Non-recursive Predictive Parsing
    14Reductions and Shift-Reduce Parsing15LR Parsing and LR(0) Parsers16LR(0) Automaton and Parsing Table17Shift-Reduce Conflicts
    18Automaton and Parsing Table
    19Automaton and Parsing Table
    20Automaton and Parsing Table21Semantic Analysis and Intermediate Code Generation22Three Address Code23Tasks of Semantic Analyzer and Types of Errors24Type Checking and Environments
    25Implicit vs Explicit26Back Patching and Switch Statements27Storage Organization and Stack Allocation of Space28Heap Management and Optimization
    29Design of a Code Generator30Target Language and Addresses in Target Code31Basic Blocks and Flow Graphs32Optimization of Basic Blocks
    4 min read
    Topic 30 of 32
    Topic Study Note Illustration
    30

    Target Language and Addresses in Target Code

    This topic belongs to the Code Generation phase of a compiler. It explains what the final output language is and how memory locations (addresses) are represented in...

    🧠 Target Language and Addresses in Target Code (Compiler Construction)

    This topic belongs to the Code Generation phase of a compiler. It explains what the final output language is and how memory locations (addresses) are represented in generated code.


    πŸ“Œ 1. Target Language

    πŸ“– Definition

    The target language is the language into which a compiler translates the source program.

    πŸ‘‰ It is the final output language of the compiler.


    🧠 Types of Target Language

    πŸ”Ή 1. Machine Language

    • Binary instructions (0s and 1s)
    • Directly executed by CPU

    πŸ”Ή 2. Assembly Language (Most Common)

    • Uses mnemonics like MOV, ADD, MUL
    • Easier to read than machine code

    πŸ”Ή 3. Intermediate Target Code

    • Sometimes pseudo-assembly is used before final machine code

    πŸ“Š Example

    Source Code:

    x = a + b;
    

    Target (Assembly Code):

    MOV R1, a
    ADD R1, b
    MOV x, R1
    

    ⭐ Key Points (Exam Important)

    βœ” Target language is final output of compiler βœ” Can be machine code or assembly code βœ” Must be efficient and executable βœ” Depends on target machine architecture


    🧠 2. Addresses in Target Code

    πŸ“– Definition

    Addresses in target code refer to the locations where data is stored or accessed during execution.

    πŸ‘‰ These may represent:

    • Memory locations
    • Registers
    • Stack locations
    • Labels (for jumps)

    🧠 3. Types of Addresses

    πŸ”Ή 1. Absolute Address

    πŸ“– Definition

    Fixed memory location in physical memory.

    Example:

    MOV R1, 5000
    

    πŸ‘‰ 5000 = fixed memory address


    πŸ”Ή 2. Relative Address

    πŸ“– Definition

    Address relative to a base register or current instruction.

    Example:

    LOAD R1, 8(R2)
    

    πŸ‘‰ Means: R2 + 8


    πŸ”Ή 3. Symbolic Address

    πŸ“– Definition

    Uses labels instead of actual memory locations.

    Example:

    L1: ADD R1, R2
    JMP L1
    

    πŸ”Ή 4. Register Address

    πŸ“– Definition

    Uses CPU registers instead of memory.

    Example:

    MOV R1, R2
    

    🧠 4. Addressing Modes in Target Code

    Addressing modes define how operands are accessed.


    πŸ”Ή 1. Immediate Addressing

    Operand is given directly.

    MOV R1, #5
    

    πŸ”Ή 2. Direct Addressing

    Memory address is given.

    MOV R1, A
    

    πŸ”Ή 3. Indirect Addressing

    Address stored in a pointer/register.

    MOV R1, (R2)
    

    πŸ”Ή 4. Indexed Addressing

    Base + offset form.

    MOV R1, 4(R2)
    

    🧠 5. Address Representation in Compiler

    During code generation, compiler assigns:

    πŸ”Ή Variables β†’ Memory addresses

    a β†’ 1000
    b β†’ 1004
    c β†’ 1008
    

    πŸ”Ή Temporary Variables

    Created during intermediate code:

    t1 = a + b
    t1 β†’ register or stack memory
    

    πŸ”Ή Labels for Control Flow

    L1, L2, L3
    

    Used in:

    • loops
    • if-else
    • switch

    🧠 6. Example of Address Translation

    Source Code:

    if (a < b)
       x = a + b;
    

    Intermediate Code:

    if a < b goto L1
    goto L2
    L1: t1 = a + b
        x = t1
    L2:
    

    Target Code:

    MOV R1, a
    CMP R1, b
    JGE L2
    
    MOV R2, a
    ADD R2, b
    MOV x, R2
    
    L2:
    

    🧠 7. Importance of Addresses in Code Generation

    βœ” Helps map variables to memory βœ” Enables correct execution flow βœ” Required for jumps and loops βœ” Used for register allocation βœ” Improves efficiency of target code


    🧠 8. Relocation of Addresses

    πŸ“– Definition

    Relocation means adjusting addresses when program is loaded into memory.


    Types:

    • Compile-time relocation
    • Load-time relocation
    • Run-time relocation

    πŸ“Š 9. Target Language vs Address Types

    Concept Meaning
    Target language Final output (assembly/machine code)
    Absolute address Fixed memory location
    Relative address Base + offset
    Symbolic address Label-based reference
    Register address CPU register usage

    πŸ“Œ 10. Key Exam Points

    βœ” Target language is final compiler output βœ” Usually assembly or machine code βœ” Addresses define memory locations of data βœ” Types: absolute, relative, symbolic, register βœ” Addressing modes control how operands are accessed βœ” Labels are used for control flow


    🎯 Final Exam Definition

    Target language is the final language produced by a compiler, usually assembly or machine code. Addresses in target code refer to the memory locations, registers, or labels used to access data and control program execution. These addresses may be absolute, relative, symbolic, or register-based depending on the addressing mode used.


    πŸ“Š FINAL REVISION TABLE

    Concept Description Example
    Target language Final output code Assembly code
    Absolute address Fixed memory 5000
    Relative address Base + offset 8(R2)
    Symbolic address Labels L1, L2
    Register address CPU registers R1, R2
    Immediate mode Constant value #5

    ← Previous topic 29
    Code Generation: Design of a Code Generator
    Next topic 31 β†’
    Basic Blocks and Flow Graphs

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    4mremaining
    705words
    Beginnerlevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Compiler Construction