An assembler is a language translator that converts a program written in assembly language into machine language or object code that the computer can use for execution.
An assembler is a language translator that converts a program written in assembly language into machine language or object code that the computer can use for execution.
Assembly language uses symbolic instructions called mnemonics, such as MOV, ADD, SUB, instead of writing binary instructions directly.
An assembler acts like a translator: it changes easy-to-read assembly instructions into machine-level instructions understood by the processor.
A computer processor directly executes machine-level instructions. Writing programs directly in binary is difficult for humans. Assembly language makes those instructions easier to write using symbolic names, and the assembler converts them into machine code.
| Item | Description |
|---|---|
| Input | Assembly language source file, usually with an .asm extension. |
| Processing | Translates mnemonics, resolves symbols and addresses. |
| Output | Object code, commonly stored in an .obj or .o file. |
The assembler reads the assembly language program, identifies instructions and symbols, determines addresses, and produces machine or object code.
Assembly language instructions generally have a one-to-one relationship with machine instructions. This means one assembly instruction corresponds closely to one machine instruction.
| Assembly Instruction | Machine Representation |
|---|---|
MOV AX, 5 |
B8 05 00 |
The assembler does not convert a whole high-level program like a compiler. Its main job is to translate assembly language into machine/object code.
A two-pass assembler processes the source program in two passes. This allows it to identify symbols and addresses before generating the final object code.
In the first pass, the assembler scans the source program and identifies labels and symbols. It records their corresponding addresses in a symbol table.
In the second pass, the assembler uses the information collected during Pass 1 to generate the actual object or machine code.
| Pass 1 | Pass 2 |
|---|---|
| Scans the source program. | Scans the source program again. |
| Builds the symbol table. | Generates object code. |
| Assigns/records addresses. | Resolves symbols and addresses. |
| Prepares information required for code generation. | Produces machine/object instructions. |
Assembly programs often use symbolic names, such as labels, instead of directly writing numeric memory addresses. The assembler keeps track of these names and their associated addresses.
A label is a name given to an instruction or memory location. The assembler later finds its actual address.
The assembler translates these assembly instructions into their corresponding machine/object representation.
| Assembler | Use |
|---|---|
| NASM | Assembler commonly used for x86 and x86-64 programming. |
| MASM | Microsoft Macro Assembler for x86-family assembly. |
| TASM | Borland Turbo Assembler. |
| Concept | Remember This |
|---|---|
| Assembler | Converts assembly language into machine/object code. |
| Input | Assembly source file, usually .asm. |
| Output | Object code, usually .obj or .o. |
| Pass 1 | Builds the symbol table and records addresses. |
| Pass 2 | Generates object code and resolves symbols. |
| Translation | Assembly instruction → Machine/Object instruction. |
| Examples | NASM, MASM, TASM. |
Pass 1 = Symbols & Addresses
Pass 2 = Machine/Object Code
After reading the topic, watch this Hindi explanation of the two-pass assembler and its working.
A short handwritten-style revision sheet covering assembler, symbol tables, Pass 1 and Pass 2 will be provided here.
Use the mind map for quick revision of assembler working, two-pass processing, symbols and object-code generation.