What is the difference between an assembler and compiler?

Last updated on November 12th, 2018

Difference between assembler and compiler:

In the development of software, there are many languages present to use.  Compilers and assemblers are some of the languages used. Compilers are made for a simple task, they just read a code or a program written for the developer of the software. These can change this code written by a man in the language of the humans to the language of the machine. This code written by man is known as the source code. This code written by man is considered a high-profile language. These compilers convert this high-profile language to the simplest language for the machine/computer which is the binary language.

A representative compiler is made up of several main components like:

  • The lexical analyzer is a scanner that reads the program and converts it to a string of tokens.
  • The Parser is the second component and it converts the tokens into an abstract syntax tree or a parse tree which captures the syntactic structure of the program.
  • The final component is the semantic routine which interprets the semantics of the syntactic structure. The code optimizations and final code generation languages like C and C++ are commonly known to have used compilers.

Compiler:

This is a program that reads a programming language, source language and translates it into a simple language known as the target language. Target languages are simple and easily understood thus referred to as a low-level language while the source language is complex, thus referred to as a high-level language. The compiler reads in whole a program written, then it converts the whole program to the machine language. Through this process, the compiler takes a substantial amount of time to read the whole program or to analyze the whole program, thus taking up lots of memory to complete their task.

Assembler:

Assembler is a compiler that translates the source language to assembly language which is a simpler language. This language is human readable language and it has a one to one relationship with the corresponding machine code. Therefore an assembler is said to perform the principle of the one to one mapping translation (Isomorphic). Assemblers currently being used today has advanced to effectively becoming not only efficient but very easy, user-friendly programs and help in the debugging of the written code as well.

Key Differences:

  • Function: A compiler generates assembly code and some compilers can also directly generate executable code while an assembler generates relocatable machine code.
  • Input: A compiler preprocessed code generated by the preprocessor while assembler takes assembly code as input.
  • Phases or Passes: In a compiler, compilation takes place in two phases that are analysis phase where the input goes through a lexical analyzer, syntax analyzer, and semantic analyzer than to the synthesis phase. Where it takes place via an intermediate code generator, a code optimizer, and a code generator while in an assembler passes the input through two phases. The first phase detects the identifiers and allows addresses to them in the second phase the assembly code is translated to binary code.
  • Output: The compiler generates an assembly, a mnemonic version of machine code. Whereas the relocatable machine code generated by an assembler is a binary relocatable code.
This entry was posted in Computer Organization and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *