3. Interpreters vs Compilers vs Assemblers in programming languages

Table of Contents
< All Topics
Print

3. Interpreters vs Compilers vs Assemblers in programming languages

  • As you know that high level language is machine independent and assembly language though it is machine dependent yet mnemonics that are being used to represent instructions are not directly understandable by the machine. Hence to make the machine understand the instructions provided by both the languages, programming language instructors are used.
  • They transform the instruction prepared by programmers into a form which can be interpreted & executed by the computer. Flowing are the various tools to achieve this purpose:

Compiler

The software that reads a program written in high level language and translates it into an equivalent program in machine language is called as compiler. The program written by the programmer in high level language is called source program and the program generated by the compiler after translation is called as object program.

Interpreter

  • it executes instructions written in a high-level language.
  • Both complier & interpreter have the same goal i.e., to convert high level language into binary instructions, but their method of execution is different.
  • The complier converts the entire source code into machine level program, while the interpreter takes 1 statement, translates it, executes it & then again takes the next statement.

Assembler

The software that reads a program written in assembly language and translates it into an equivalent program in machine language is called as assembler.

  • Assembler is a program for converting instructions written in low-level assembly code into relocatable machine code and generating along information for the loader.
  • Low level machine codes are also known as pnemonices. These are special words to define basic operations on binary data. example ADD, MULT, SQR, DIV, SUB etc.
  • It generates instructions by evaluating the mnemonics (symbols) in operation field and find the value of symbol and literals to produce machine code.

Linker

A linker or link editor is a computer program that takes one or more object files generated by a compiler and combines them into a single executable file, library file, or another object file.

Comparison: Compiler vs Assembler

Compiler Vs Assembler
BASIS OF COMPARISONCOMPILERASSEMBLER
TranslationCompiler converts the source code written by the programmer to a machine level language.Assembler converts the assembly code into the machine code.
Take Input asCompiler inputs is preprocessed source code.Assembler inputs source code.
Gives output asThe output of compiler is a mnemonic version of machine code.The output of assembler is binary code.
ExamplesCGAS
C#GNU
JavaASM
C++
DebuggingDebugging is easy.Debugging is difficult.
WorkingComplier scans the entire program first before translating into machine code.Assembler converts source code to an object code first then it converts the object code to the machine language with the help of linker programs.
IntelligenceCompiler is more intelligent than assembler.Assembler is less intelligent than a compiler.
Working PhasesThe compilation phases are:
Lexical analyzer
Syntax analyzer
Semantic analyzer
Code optimizer
Code generator
Assembler makes works in two phases over the given input. The phases are:
First Phase
Second Phase
Table to show comparison between complier and assembler.

Comparison: Interpreter vs Compiler

Working of Compiler and interpreter
BASIS OF COMPARISONINTERPRETERCOMPILER
FunctionInterpreter converts source code into the intermediate form and then converts that intermediate code into machine languageA compiler converts high-level language program code into machine language and then executes it.
ScanningInterpreter scans and translates the program line by line to equivalent machine code.Complier scans the entire program first before translating into machine code.
WorkingInterpreter takes single instruction as input.Compiler takes entire program as input.
Code GenerationIn case of interpreter, No intermediate object code is generated.Intermediate object code is generated in case of compiler.
Execution TimeInterpreter takes more execution time when compared to compiler.Compiler takes less execution time when compared to interpreter.
ExamplesPythonC, C++, Cobol, C# etc.
PerlCOBOL
VBC#
PostScriptC++, etc
LISP etc.
Memory RequirementInterpreter needs less memory when compared to compiler.Compiler requires more memory than interpreter.
ModificationIf you make any modification and if that line has not been scanned then no need to recompile entire program.If you happen to make any modification in program you have to recompile entire program i.e scan the whole program every time after modification.
SpeedInterpreter is slower when compared to compiler.Compiler is faster when compared to interpreter.
At ExecutionEvery time program is scanned and translated at execution time.There is usually no need to compile program every time (if not modified) at execution time.
Error DetectionInterpreter stops the translation at the error generation and will continue when error get solved.Compiler gives you the list of all errors after compilation of whole program.
Machine CodeEach time the program is executed; every line is checked for error and then converted into equivalent machine code.Compiler converts the entire program to machine code when all errors are removed execution takes place.
DebuggingInterpreter is good for fast debugging.Compiler is slow for debugging because errors are displayed after entire program has been checked.
Code VersionAt the output of assembler is re-locatable machine code generated by an assembler represented by binary code.The assembly code generated by the compiler is a mnemonic version of machine code.
BASIS OF COMPARISONINTERPRETERCOMPILER
Table to comparison between Interpreter and compiler

Leave a comment