• Networking
  • Programming
  • DBMS
  • Operating System
  • Internet
  • Hardware
  • Software

Tech Differences

Know the Technical Differences

Difference Between Compiler and Assembler

Compiler Vs AssemblerCompiler and Assembler plays an important role in the execution of a program. Some compilers directly generate the executable code instead of assembly code. The compiler takes the preprocessed source code and translates it into the assembly code. The assembler takes the assembly code from the compiler and translates it to the relocatable machine code.

In this article, I have discussed the differences between compiler and assembler with the help of comparison chart shown below, just have a look.

Content: Compiler Vs Assembler

  1. Comparison Chart
  2. Definition
  3. Key Differences
  4. Conclusion

Comparison Chart

Basis for ComparisonCompiler Assembler
BasicGenerates the assembly language code or directly the executable code.Generates the relocatable machine code.
InputPreprocessed source code.Assembly language code.
Phases/ PassesThe compilation phases are lexical analyzer, syntax analyzer, semantic analyzer, intermediate code generation, code optimization, code generation.Assembler makes two passes over the given input.
OutputThe assembly code generated by the compiler is a mnemonic version of machine code.The relocatable machine code generated by an assembler is represented by binary code.

Definition of Compiler

The compiler is a computer program that reads the program written in a source language, translates it into equivalent assembly language and forwards the assembly language code to the Assembler. While the translation of the source code to assembly code the compiler also reports the error in the source code to its user.

Compilers are also classified as single-pass, multi-pass, load-and-go, debugging and optimization. Classification is done on the basis of what function does a compiler perform and how it has been constructed. Despite these complexities, the basic task of compiler remains same.

The compilation is performed in two parts, analysis part and synthesis part. The analysis part breaks the source code into constituent pieces and forms the intermediate representation of the source code. The synthesis part forms the target code from the intermediate representation.

The compilation is performed in the following phases:

Lexical analyzer, syntax analyzer, semantic analyzer, intermediate code generator, code optimizer, code generator, Symbol table and error Handler.

Compiler example

  • The lexical analyzer reads the characters of source code and groups them into the streams of tokens. Each token represents the logical sequence of characters like keyword, identifiers, operators. The sequence of character that forms a token is called lexeme.
  • The syntax analyzer parses the token obtained from lexical analyzer and groups tokens into a hierarchical structure.
  • The semantic analyzer checks the source code for any semantic error.
  • Intermediate code generator generates the intermediate representation of the source code
  • The code Optimizer optimizes the intermediate code into faster running machine code.
  • The code generator finally generates the target code which is a relocatable machine code or an assembly code.
  • The symbol table is a data structure which contains the record for each identifier in the source code.
  • Error handler detects the error in each phase and handles those errors.

Definition of Assembler

Some compilers perform the task of assembler and directly generate a relocatable machine code instead of assembly code, which is further directly passed to linker /loader. The assembler takes as input the assembly code generated by the compiler and translates it into relocatable machine code.

AssemblerLet us see how machine code is different from assembly code. Assembly code is the mnemonic version of machine code. It means it assembly code uses names for representing operations and it even gives names to the memory addresses. On the other hands, the machine code uses binary codes for representation of operations and memory addresses.

Even the simplest form of assembler performs two passes over the input. The first pass detects all the identifiers in the assembly code that denotes storage location and store them in the symbol table (other than compilers symbol table). The storage location is assigned to the identifier that is encountered in the first pass.

In the second pass, the input is scanned again, and this time the operation code are translated into a sequence of bits representing that operation in the machine code. The second pass also translates identifiers into the addresses defined in the symbol table. Thus the second pass generates the relocatable machine code.

Key Differences Between Compiler and Assembler

  1. The key difference between compiler and assembler is that the compiler generates assembly code and some compilers can also directly generate executable code whereas, the assembler generates relocatable machine code.
  2. The compiler takes as input the preprocessed code generated by preprocessor. On the other hands, the assembler takes assembly code as input.
  3. The compilation takes place in two phases that are analysis phase and synthesis phase. In analysis phase, the input goes through lexical analyzer, syntax analyzer, semantic analyzer whereas, the synthesis analysis takes place via intermediate code generator, code optimizer, code generator. On the other hands, assembler passes the input through two phases. The first phase detects the identifiers and allots addresses to them in the second phase the assembly code is translated to binary code.
  4. The assembly code generated by the compiler is a mnemonic version of machine code. However, the relocatable machine code generated by assembler is a binary relocatable code.

Conclusion

The assembler may not be required as some compilers directly generate executable code. If assembler is used it requires linker to link all the built-in libraries to the library functions used in the source code.

Related Differences:

  1. Difference Between Compiler and Interpreter
  2. Difference Between Linker and Loader
  3. Difference Between High-Level Language and Low-Level Language
  4. Difference Between Aggregation and Composition
  5. Difference Between Agile and Waterfall

Comments

  1. Hidayat Ullah says

    October 11, 2018 at 6:27 pm

    Nicely explained

    Reply
  2. Subhashis says

    May 28, 2019 at 10:06 pm

    Your Explanation is awesome, but can you please add Examples?

    Reply
  3. kevin says

    November 21, 2019 at 7:45 am

    Nice Content

    Reply

Leave a Reply Cancel reply

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

Top 10 Differences

  • Difference Between OLTP and OLAP
  • Difference Between while and do-while Loop
  • Difference Between Guided and Unguided Media
  • Difference Between Preemptive and Non-Preemptive Scheduling in OS
  • Difference Between LAN, MAN and WAN
  • Difference Between if-else and switch
  • Difference Between dispose() and finalize() in C#
  • Difference Between for and while loop
  • Difference Between View and Materialized View
  • Difference Between Server-side Scripting and Client-side Scripting

Recent Addition

  • Difference Between Java and Python
  • Difference Between PHP and HTML
  • Difference Between GPS and GNSS 
  • Difference Between Virtualization and Containerization
  • Difference Between Storage and Memory

Categories

  • Artificial Intelligence
  • DBMS
  • Hardware
  • Internet
  • Networking
  • Operating System
  • Programming
  • Software

Copyright © 2025 · Tech Differences · Contact Us · About Us · Privacy