ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Compiler Construction
    COMP3149
    Progress0 / 32 topics
    Topics
    1. Introduction to interpreter and compiler2. Structure of a Compiler and its Phases3. Lexical Analyzer and Input Buffering4. Specifications and Recognitions of Tokens5. Regular Expressions and Finite Automata6. Transition Table and Transition Graph7. Definitions of Grammars, Derivations, and Parse Trees8. Ambiguity, Associativity, and Precedence of Operators9. Syntax Analysis and Role of the Parser10. Eliminating Ambiguity, Left Recursion, and Left Factoring11. Top-Down Parsing and Recursive-Descent Parsing12. First and Follow Sets13. LL(1) Grammars and Non-recursive Predictive Parsing14. Bottom-Up Parsing: Reductions and Shift-Reduce Parsing15. LR Parsing and LR(0) Parsers16. LR(0) Automaton and Parsing Table17. Shift-Reduce Conflicts18. SLR(1) Parsers: Automaton and Parsing Table19. LR(1) Parsers: Automaton and Parsing Table20. LALR Parsing: Automaton and Parsing Table21. Semantic Analysis and Intermediate Code Generation22. Three Address Code23. Tasks of Semantic Analyzer and Types of Errors24. Type Checking and Environments25. Type Conversions: Implicit vs Explicit26. Back Patching and Switch Statements27. Storage Organization and Stack Allocation of Space28. Heap Management and Optimization29. Code Generation: Design of a Code Generator30. Target Language and Addresses in Target Code31. Basic Blocks and Flow Graphs32. Optimization of Basic Blocks
    COMP3149›Target Language and Addresses in Target Code
    Compiler ConstructionTopic 30 of 32

    Target Language and Addresses in Target Code

    4 minread
    705words
    Beginnerlevel

    🧠 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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time4 min
      Word count705
      Code examples0
      DifficultyBeginner