Compiler vs Interpreter (and Friends: Assembler, Linker, Loader)

Compiler vs Interpreter (and Friends: Assembler, Linker, Loader)


Computers only execute machine language (binary).

What we write is source code in human-friendly languages.

We therefore need translator software to bridge the gap: compilers (ahead-of-time), interpreters (line-by-line), and assemblers (assembly → machine).

We’ll also see where linkers, libraries, .exe files, and loaders fit in the journey from source to running program.


🔹 1) Why a Translator?

  • We write high-level code (e.g., PRINT "Name : Mohammed").
  • CPU runs machine language.
  • A translator converts source code → object/machine code so the computer can execute it.


🔹 2) The Compiler Pipeline (end-to-end)


Input: Source code 👉 Compiler 👉 Object code + Libraries 👉 Linker 👉 .exe file (saved on disk) 👉 Loader loads it into memory 👉 Program runs and prints output (e.g., Name : Mohammed, Age : 44).

  • Compiler (build time): translates the entire program and reports build errors if found. If errors exist → stop; otherwise produce object code.
  • Linker: combines object code with libraries to create an executable (.exe), stored on HDD/SSD.
  • Loader (run time): loads the .exe into memory and starts execution.
machine code is stored on disk, .exe generated, and execution is fast.


🔹 3) How a Compiler Works and Handles Errors?

  1. Scan entire program.
  2. If build errors?display error message and stop.
  3. If no errors → continue to produce object code and link.


🔹 4) How a Interpreter Works and Handles Errors?

  • Reads one instruction at a time, translates it to machine code on the fly, then executes immediately.
  • If an error occurs → display error message and stop at that line.
  • No .exe is produced; no machine code is saved on disk.
  • Execution is generally slower.


🔹 5) Which Is Faster Compiled or Interpreted Languages?


Compiled languages are much faster than interpreted languages.


🔹 6) Differences Between Complied and Interpreted Code?


🔹 7) What Is an Assembler?

Assembler: the program that translates assembly code to machine code.


🔗 Interconnection

  • High-level source needs a translator to become machine code.
  • Compiler path: Source → Object → (Linker + Libraries) → .exeLoader → Run. Fast, reusable binary.
  • Interpreter path: Line-by-line translate & run. No .exe, typically slower.


By mastering these flows, learners can choose the right toolchain and predict build/run behavior with confidence. 🚀


12-Programming Foundations - Compiler vs Interpreter.pdf
Complete and Continue  
Discussion

0 comments