Assembler vs. Compiler: What's the Difference?

Advertisement

Key Difference

The difference between assembler and compiler is that compiler takes the source code and translates it into the assembly code whereas assembler takes the assembly code generated by the compiler and translates it into the machine code.

Advertisement

Assembler vs. Compiler

Two terms that play the most important role in the program execution is compiler and assembler. The job of the compiler is to take the preprocessed source code and translate it into the assembly code. Then the job of assembler is to takes the assembly code from the compiler and translates it to the machine code. If we talk about the main difference, then the main difference between assembler and compiler is that compiler takes the source code and translates it into the assembly code whereas assembler takes the assembly code generated by the compiler and translates it into the machine code. The program that is written in a source language is read by compiler. The compiler is a computer program that translates the source code into the assembly language, and this assembly language code is sent to the assembler. There are types of compilers such as single pass compiler, multi-pass compiler, load and go compiler and debugging and optimization compiler. Assembler takes the assembly code generated by the compiler and translates it into the machine code. The main job of assembler is to take the data as input and form the relocatable machine code. There is compiler available that perform the task of the assembler and directly generate the machine code but that does not mean we cannot study the functions of assembler. There is a lot of difference between assembly code and machine code. All of these different type of compilers perform different functions and are different on the basis of working. Assembly code is the mnemonic version of machine code whereas machine code uses the binary codes for the representation of operations of memory address. Two passes are preform in assembler that are first pass that identifies the assembly code and store that code in symbol table and then second pass that scan the code again and perform the operations on the code. There are two steps in which compiling is performed one step is analysis part in which the source code is broken into pieces and perform the intermediate representation. In synthesis part the target code is form the intermediate representation. There are phases of the compiler that are a lexical analyzer, syntax analyzer, semantic analyze, intermediate code generate, a code optimizer, code generator, symbol table and error handler.

Advertisement

Comparison Chart

BasisAssemblerCompiler
MeaningAssembler is a computer program that takes the assembly code generated by the compiler and translates it into the machine codeThe compiler is a computer program that takes the source code and translates it into the assembly code
InputAssembler input assembly language codeCompiler input source code
Phases Phases of assembler are the first phase and the second phase.Phases of the compiler are a lexical analyzer, syntax analyzer, semantic analyze, intermediate code generated, a code optimizer, code generator, symbol table and error handler
OutputThe output of assembler is binary codeThe output of compiler is a mnemonic version of the code.

 What is a Compiler?

The program that is written in a source language is read by compiler. The compiler is a computer program that translates the source code into the assembly language, and this assembly language code is sent to the assembler. There are types of compilers such as single pass compiler, multi-pass compiler, load and go compiler and debugging and optimization compiler. All of these different types of compilers perform different functions and are different on the basis of working. There are two steps in which compiling is performed one step is the analysis part in which the source code is broken into pieces and perform the intermediate representation. In synthesis part, the target code forms the intermediate representation. There are phases of the compiler that are a lexical analyzer, syntax analyzer, semantic analyze, intermediate code generates, a code optimizer, code generator, symbol table and error handler.

Advertisement

Assembler and complier are not the same processes, but they do same work that is they generate the object code of a source program and hands it to the linker. The main process of the linker is to take the object code and generate the executable code for the program after this work of linker is finished, and it assigns the code to the loader. There are some built in libraries and header files in high level language. There are some library functions which are defined in built in libraries. These functions are linked to a library function by the linker. The complier is being informed in the case if library function is not found of the particular function. When there is a large program, then it is divided into smaller programs that are known as modules. Object modules are generated when these modules are compiled or assembled. Linker have to combine the whole program together. There are two types of linker one is linkage editor that generates relocated, executable module and other is a dynamic linker that linkage the external modules until the load module is generated. The program that has to be executed is present in main memory. Loader, load the executable file in the operating system. Loader allocates the memory space to the executable module in the main memory. There are three types of the loader that are: absolute loader, relocatable loader and dynamic run time loading. These three loaders have different loading approaches that are absolute loading approach, relocatable loading approach and dynamic run time loading approach. The absolute loader loads the executable file of the program into the same main memory location. In absolute loader, the programmer must be aware of the assignment. Relocating loader compile or assemble actual main memory address. Dynamic run time loader, absolute memory program is generated when an instruction is executed.

What is Assembler?

Assembler takes the assembly code generated by the compiler and translates it into the machine code. The main job of assembler is to take the data as input and form the relocatable machine code. There is compiler available that perform the task of the assembler and directly generate the machine code, but that does not mean we cannot study the functions of assembler. There is a lot of difference between assembly code and machine code. Assembly code is the mnemonic version of machine code whereas machine code uses the binary codes for the representation of operations of the memory address. Two passes are preform in assembler that is the first pass that identifies the assembly code and stores that code in the symbol table and then the second pass that scans the code again and performs the operations on the code.

Key Differences

  1. Assembler is a computer program that takes the assembly code generated by the compiler and translates it into the machine code whereas Compiler is a computer program that takes the source code and translates it into the assembly code.
  2. Assembler input assembly language code whereas Compiler input source code.
  3. Phases of assembler are first phase and a second phase, Phases of the compiler are a lexical analyzer, syntax analyzer, semantic analyze, intermediate code generated, a code optimizer, code generator, symbol table and error handler.
  4. The output of assembler is binary code whereas Output of compiler is a mnemonic version of the code.

Explanatory Video