Compiler, Assembler and Interpreter

4
2506

Compiler, Assembler and Interpreter

compiler_interpreterIt is difficult to write and maintain programs in machine level language. The programs written in the code of high level language and low level language need to be converted into machine level language using translators for this purpose. Translators are just computer programs which accept a program written in high level or low level language and produce an equivalent machine level program as output. Translators are of three types:

COMPILER: It is a program which translates a high level language program into a machine language program. A compiler is more intelligent than an assembler. It checks all kinds of limits, ranges, errors etc. But its program run time is more and occupies a larger part of the memory. It has slow speed. Because a compiler goes through the entire program and then translates the entire program into machine codes. If a compiler runs on a computer and produces the machine codes for the same computer then it is known as a self-compiler or resident compiler. On the other hand, if a compiler runs on a computer and produces the machine codes for other computer then it is known as a cross compiler.

Advantages:

  • Source code is not included, therefore compiled code is more secure than interpreted code
  • Tends to produce faster code than interpreting source code
  • Produces an executable file, and therefore the program can be run without need of the source code

Disadvantages:

  • Object code needs to be produced before a final executable file, this can be a slow process
  • The source code must be 100% correct for the executable file to be produced

Example: GCC, Microsoft Visual Studio

INTERPRETER: An interpreter is a program which translates statements of a program into machine code. It translates only one statement of the program at a time. It reads only one statement of program, translates it and executes it. Then it reads the next statement of the program again translates it and executes it. In this way it proceeds further till all the statements are translated and executed.

Advantages:

  • Easier to debug(check errors) than a compiler
  • Easier to create multi-platform code, as each different platform would have an interpreter to run the same code
  • Useful for prototyping software and testing basic program logic

Disadvantages:

  • Source code is required for the program to be executed, and this source code can be read making it insecure
  • Interpreters are generally slower than compiled programs due to the per-line translation method

Example: Python, LISP, Ocamle

ASSEMBLER: A computer will not understand any program written in a language, other than its machine language. The programs written in other languages must be translated into the machine language. Such translation is performed with the help of software. A program which translates an assembly language program into a machine language program is called an assembler. If an assembler which runs on a computer and produces the machine codes for the same computer then it is called self-assembler or resident assembler. If an assembler that runs on a computer and produces the machine codes for other computer then it is called Cross Assembler.

Advantages:

  • Very fast in translating assembly language to machine code as 1 to 1 relationship
  • Assembly code is often very efficient (and therefore fast) because it is a low level language
  • Assembly code is fairly easy to understand due to the use of English-like mnemonics

 

Disadvantages:

  • Assembly language is written for a certain instruction set and/or processor
  • Assembly tends to be optimized for the hardware it’s designed for, meaning it is often incompatible with different hardware
  • Lots of assembly code is needed to do relatively simple tasks, and complex programs require lots of programming time.

             Example: MASM, NASM.