In conventional computers, translation of the program or the source code into object/machine code is done by various methods which include assembler, compiler and interpreter. Below are the underlying details of how they differ from one another.
What You Need To Know About Assembler
An assembler is a program that takes basic computer instruction or instructions and then converts them into a pattern of bits that the computer processor can use to perform its basic operations. Usually, language used to program the assembler is referred to as assembly language. Assembler converts source code to an object code first then it converts the object code to machine language with the help of the linker programs.
Details About Assembler
- Assembler converts source code written in assembly language into machine code and then that machine code is executed by a computer.
- Assembler converts assembly language to machine language at once.
- It converts a source code to an object first then it converts the object code to machine language with the linker programs.
- Input to the assembler is assembly language code.
- GAS, GNU is an example of an assembler.
- At the output of assembler is re-locatable machine code generated by an assembler is represented by binary code.
- Assembler cannot convert the whole code into machine language at once.
- Assembler is less intelligent than compiler.
- Assembler makes two phases over the given input first phase and the second phase.
- It is difficult to debugging.
What You Need To Know About Complier
A compiler is a computer program that transforms source code written in programming language into machine language and then executes it. Normally, Compilers can take time because they have to translate high-level code to lower-level machine language at once and then save the executable object code to the memory. Also in a compiler, after conversion of all the code at once an error report for the whole program is generated.
Compilers can be classified based on what function it performs or how it has been constructed. Compilers can be classified as single-pass, load-and-go, debugging, multi-pass and optimization.
Compilation is performed in the following phases: lexical analyzer, syntax analyzer, semantic analyzer, intermediate code generator, code optimizer, symbol table and error handle.
Details About Compiler
- A compiler converts high-level language program code into machine language and then executes it. High-level languages are C and C#
- Complier scans the entire program first before translating into machine code.
- Compiler takes entire program as input.
- Intermediate object code is generated in case of compiler.
- Compiler takes less execution time when compared to interpreter.
- Examples include C, COBOL, C#, C++, etc
- Compiler requires more memory than interpreter.
- 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.
- Compiler is faster when compared to interpreter.
- There is usually no need to compile program every time (if not modified) at execution time.
- Compiler gives you the list of all errors after compilation of whole program.
- Compiler converts the entire program to machine code when all errors are removed execution takes place.
- Compiler is slow for debugging because errors are displayed after entire program has been checked.
- The assembly code generated by the compiler is a mnemonic version of machine code.
What You Need To Know About Interpreter
Interpreter is a computer program that translates high level instructions into an intermediate form and then converts that intermediate code into machine language and; carries out specific actions. Interpreters are often used in software development tools as debugging tools because they can execute a single code at a time. In Java language, compiler and interpreter work together to generate machine code.
Details About Interpreter
- Interpreter converts source code into the intermediate form and then converts that intermediate code into machine language. The intermediate code looks same as assembler code.
- Interpreter scans and translates the program line by line to equivalent machine code.
- Interpreter takes single instruction as input.
- In case of interpreter, No intermediate object code is generated.
- Interpreter takes more execution time when compared to compiler.
- Examples include Python, Perl, VB, PostScript, LISP etc.
- Interpreter needs less memory when compared to compiler.
- If you make any modification and if that line has not been scanned then no need to recompile entire program.
- Interpreter is slower when compared to compiler.
- Every time program is scanned and translated at execution time.
- Interpreter stops the translation at the error generation and will continue when error get solved.
- Each time the program is executed; every line is checked for error and then converted into equivalent machine code.
- Interpreter is good for fast debugging. An interpreter continues translating the program until the first error is arrived at, in which case it stops.
- At the output of assembler is re-locatable machine code generated by an assembler represented by binary code.
Difference Between Assembler, Compiler And Interpreter In Tabular Form
Assembler Vs Compiler
BASIS OF COMPARISON | ASSEMBLER | COMPILER |
Conversion | Assembler converts the assembly code into the machine code. | Compiler converts the source code written by the programmer to a machine level language. |
Input | Assembler inputs source code. | Compiler inputs is preprocessed source code. |
The output | The output of assembler is binary code. | The output of compiler is a mnemonic version of machine code. |
Examples | GAS GNU | C C# Java C++ |
Debugging | Debugging is difficult. | Debugging is easy. |
Working | 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. | Complier scans the entire program first before translating into machine code. |
Intelligence | Assembler is less intelligent than a compiler. | Compiler is more intelligent than assembler. |
Working Phases | Assembler makes works in two phases over the given input. The phases are: First Phase Second Phase | The compilation phases are: Lexical analyzer Syntax analyzer Semantic analyzer Code optimizer Code generator Error handler |
Compiler Vs Interpreter
BASIS OF COMPARISON | COMPILER | INTERPRETER |
Function | A compiler converts high-level language program code into machine language and then executes it. | Interpreter converts source code into the intermediate form and then converts that intermediate code into machine language |
Scanning | Complier scans the entire program first before translating into machine code. | Interpreter scans and translates the program line by line to equivalent machine code. |
Working | Compiler takes entire program as input. | Interpreter takes single instruction as input. |
Code Generation | Intermediate object code is generated in case of compiler. | In case of interpreter, No intermediate object code is generated. |
Execution Time | Compiler takes less execution time when compared to interpreter. | Interpreter takes more execution time when compared to compiler. |
Examples | C COBOL C# C++, etc | Python Perl VB PostScript LISP etc. |
Memory Requirement | Compiler requires more memory than interpreter. | Interpreter needs less memory when compared to compiler. |
Modification | 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. | If you make any modification and if that line has not been scanned then no need to recompile entire program. |
Speed | Compiler is faster when compared to interpreter. | Interpreter is slower when compared to compiler. |
At Execution | There is usually no need to compile program every time (if not modified) at execution time. | Every time program is scanned and translated at execution time. |
Error Detection | Compiler gives you the list of all errors after compilation of whole program. | Interpreter stops the translation at the error generation and will continue when error get solved. |
Machine Code | Compiler converts the entire program to machine code when all errors are removed execution takes place. | Each time the program is executed; every line is checked for error and then converted into equivalent machine code. |
Debugging | Compiler is slow for debugging because errors are displayed after entire program has been checked. | Interpreter is good for fast debugging. |
Code Version | The assembly code generated by the compiler is a mnemonic version of machine code. | At the output of assembler is re-locatable machine code generated by an assembler represented by binary code. |