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) β†’ .exe β†’ Loader β†’ 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

7 comments