Assembler

The Assembler is a Software that converts an assembly language code to machine code. It takes basic Computer commands and converts them into Binary Code that Computer’s Processor can use to perform its Basic Operations. These instructions are assembler language or assembly language.

We can also name an assembler as the compiler of assembly language. This is because a compiler converts the high-level language to machine language. On the other hand, an assembler is doing the same task but, for assembly language, the name compiler of assembly language.

What is an Assembly Language?

An assembly language is a low-level language. It gives instructions to the processors for different tasks. It is specific for any processor. The machine language only consists of 0s and 1s therefore, it is difficult to write a program in it. On the other hand, the assembly language is close to a machine language but has a simpler language and code.

We can create an assembly language code using a compiler or, a programmer can write it directly. Mostly, programmers use high-level languages but, when more specific code is required, assembly language is used. It uses opcode for the instructions. An opcode basically gives information about the particular instruction. The symbolic representation of the opcode (machine level instruction) is called mnemonics. Programmers use them to remember the operations in assembly language.

For example ADD A,B

Here, ADD is the mnemonic that tells the processor that it has to perform additional function. Moreover, A and B are the operands. Also, SUB, MUL, DIVC, etc. are other mnemonics.

Types of Assembler

Assemblers generate instruction. On the basis of a number of phases used to convert to machine code, assemblers have two types:

1. One-Pass Assembler

These assemblers perform the whole conversion of assembly code to machine code in one go.

2. Multi-Pass/Two-Pass Assembler

These assemblers first process the assembly code and store values in the opcode table and symbol table. And then in the second step, they generate the machine code using these tables.

a) Pass 1

  • Symbol table and opcode tables are defined.
  • keep the record of the location counter.
  • Also, processes the pseudo instructions.

b) Pass 2

  • Finally, converts the opcode into the corresponding numeric opcode.
  • Generates machine code according to values of literals and symbols.

Some Important Terms

  • Opcode table: They store the value of mnemonics and their corresponding numeric values.
  • Symbol table: They store the value of programming language symbols used by the programmer, and their corresponding numeric values.
  • Location Counter: It stores the address of the location where the current instruction will be stored.

Differences Between Compiler and Assembler

CompilerAssembler
Compiler converts the high-level language source code into machine level language code.An assembler converts the assembly level language code into the machine level language code.
The input of a compiler is high-level language source code.Where as, its input is low level assembly code.
Compiler converts the whole source code to machine code at once.Assembler does not convert the code in one go.
It has the following phases: lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation and error handling.An assembler completes the task in two passes.
It produces a machine code in form of mnemonics.It produces binary code in form of 0s and 1s.
Examples are Java, C, C++ etc. compilers.Examples of assemblers are GAS, GNU etc.

Frequently Asked Questions (FAQs)

Q1. What is an assembler?

A1. An assembler is software that converts the assembly language code into machine code (binary language).

Q2. What is an assembly language?

A2. An assembly language is a low-level language. In addition, it is specific for each processor and give the instructions to a processor. Moreover, it uses mnemonics for the instructions.

Q3. What are mnemonics?

A3. Mnemonics are the symbolic representation of machine-level instructions. Moreover, it is used by programmers so that they can remember machine level processes easily.

Q4. What are the types of assembler?

A4. On the basis of passes it has two types as follows:

  • One-pass assembler
  • Multi-pass/two-pass assembler

Q5. What is the basic difference between a compiler and an assembler?

A5. A compiler converts the high-level language code into machine code, on the other hand, an assembler converts the assembly language code into machine code (binary language).

Read More

error: Content is protected !!