🖥️

Compiler Design - Introduction

Jul 2, 2024

Compiler Design - Lecture Notes

Introduction to Compiler

What is a Compiler?

  • A compiler is a software that converts a program written in a High Level Language (HLL) to a Low Level Language (LLL).
  • Source language (HLL): For example, Java, C programs written using English alphabets.
  • Target language (LLL): Assembly language or machine level language that the system can understand.

Role of the Compiler

  • Converts high level language to low level language for system processing.
  • Example process: Java/C high level code -> Low level language -> Machine code.

Language Processing System

Stages of Language Processing

  1. Source Code (High Level Language)
  2. Preprocessor
    • Removes include directives (e.g., #include, #define in C).
    • Performs file inclusions, augmentations, and macro processing.
  3. Compiler
    • Translates the program from high level language to assembly language (low level language).
  4. Assembler
    • Translates assembly language (low level) to machine language (object code).
  5. Loader/Linker
    • Loads and links all parts of the program together for execution.
    • Generates relocatable machine code which can be loaded and run at any point in memory.

Detailed Steps

  • Preprocessor: Removes directives like #include, #define and replaces them with appropriate code inclusions.
  • Compiler (focus): Converts high level language code to low level language (mnemonics like ADD, MOV).
  • Assembler: Converts low level language to machine code (binary numbers).
  • Loader/Linker: Links library functions and loads the machine code into memory for execution.

Example: C Program Compilation

  • Writing a C program using high level language.
  • C Compiler: Converts high level language to low level language (assembly).
  • Assembler: Converts low level assembly language to machine code (object code).
  • Linker: Links all parts of the program together including necessary library functions.
  • Loader: Loads all linked parts into memory and executes the program.

Key Points

  • Compiler: High Level Language to Low Level Language (Assembly).
  • Assembler: Low Level Language to Machine Language (Binary code).
  • Statements are converted to mnemonics, and mnemonics are converted to binary numbers (machine code).

Focus on Compiler

  • Compiler's Role: Convert high level language to assembly language.
  • Internal Process: Understand statements into mnemonics conversion and mnemonics into binary code.

Summary

  • High Level Language (Source Code)
  • Compiler -> Low Level Language (Assembly, mnemonics)
  • Assembler -> Machine Language (Binary)
  • Linker/Loader -> Executes program in memory.

Thank you.