Two pass assembler
Two-Pass Assembler

Assembly Language

Page Contents

Assembly Language is a low-level programming language that is used for a computer or other programmable devices. There is a very strong correspondence between the assembly language and the architecture’s machine code instructions.

Every assembly language is system-specific i.e, it is unique for every individual system that it operates on which is exactly opposite to the high-level languages where the language is portable from device to device. but require interpreting or compiling.

Assembly language uses a mnemonic to represent each low-level machine operation or opcode. Some opcodes require one or more OPERANDS as part of the instruction.

Design of two Pass Assemblers

An assembler is a translator, that translates an assembler program into a conventional machine language program. Basically, the assembler goes through the program one line at a time and generates machine code for that instruction. Let us see two-pass assemblers

Then the assembler processes to the next instruction. In this way, the entire machine code program is created

What is the difference between one pass and two pass assembler?


It is an assembler that generally generates the object code directly in memory for immediate execution. It parses through your source code only once and you are done. Now let us see how a two pass assembler works. Simple, while on its way, if the assembler encounters an undefined label, it puts it into a symbol table along with the address where the undefined symbol’s value has to be placed when the symbol is found in future


As explained, the one-pass assembler cannot resolve forward references of data symbols. It requires all data symbols to be defined prior to being used. A two-pass assembler solves this dilemma by devoting one pass to exclusively resolve all (data/label) forward references and then generate object code with no hassles in the next pass. If a data symbol depends on another and this another depends on yet another, the assembler resolved this recursively. If I try explaining even that in this post, the post will become too big. Read this ppt for more details

What is System Programming?

 Linear Convolution

Advantages of Two Pass Assembler

One of the main advantages of Two-Pass Assembler is that many times the first pass of an extreme Two-pass assembler generates the output file which is then read by the second pass.

The advantage of this is that first pass can record each line of input, along with that the next position of some or all lexemes of that line and some of the results of parsing.

For example, in an assembly-level language, each line can be sent to the other line by a record indicating if the line was a definition or a statement and if statement then if it contained a label and what was the value of the location counter was before processing that line.

The use of such kind of intermediate files can eliminate unnecessary computations in the two-pass assembler but then it adds to the input-output burden of the system

Topics covered:

How does 2 pass assembler work?
2 pass assembler algorithm.
2 pass assembler Design.
2 pass assembler program



Advanced Assembler Directives

  2. EQU
  3. LT ORG

Pass I of the Assembler

Data Structure used in Pass I

  1. OPTA

Intermediate code
Declaration and Assembler Directive Processing

Pass II of the Assembler

assembler system programming operating system


  • Convert mnemonic operation codes to their machine language equivalents
  • Convert symbolic operands to their equivalent machine addresses
  • Build the machine instructions in the proper format
  • Convert the data constants to internal machine representations
  • Write the object program and the assembly listing

Two Pass Assembler

  • Read from input line
two pass assembler
Two Pass Assembler

Design of 2 – Pass Assembler


  1. Separate the Symbol, Mnemonic opcode, and operand fields
  2. Build the symbol table
  3. Perform LC Processing
  4. Construct Intermediate Representation



 Advanced Assembler Directives

  • EQU

ORIGIN Syntax:
ORIGIN < Address Specification>

Advanced Assembler Directives
 Advanced Assembler Directives

<Symbol> EQU <Address Specification>E.g.     MAXLEN    EQU    4096  Pass I of Assembler 

  • Pass I Use following Data Structures
    • OPTAB
    • SYMTAB
    • LITTAB


SYMTAB: Symbol Table

SYMTAB: Symbol Table

LITTAB: Table of Literals used in program  

LITTAB: Table of Literals used in program

POOLTAB: A table of information concerning literal pool 

POOLTAB: A table of information concerning literal pool



The main reason why most assemblers use a 2-pass system is to address the problem of forwarding references — references to variables or subroutines that have not yet been encountered when parsing the source code. A strict 1-pass scanner cannot assemble source code which contains forward references. Pass 1 of the assembler scans the source, determining the size and address of all data and instructions; then pass 2 scans the source again, outputting the binary object code. Some assemblers have been written to use a 1.5 pass scheme, whereby the source is only scanned once, but any forward references are simply assumed to be of the largest size necessary to hold any native machine data type. The unknown quantity is temporarily filled in as zero during pass 1 of the assembler, and the forward reference is added to a ‘fix-up list’. After pass 1, the ‘.5’ the pass goes through the fix-up list and patches the output machine code with the values of all resolved forward references. This can result in sub-optimal opcode construction but allows for a very fast assembly phase.


One Pass Assembler The one pass assembler passes over the file once, that is it collects all the information in one loop. It Collects labels and also resolves future references There is a major problem of future referencing Assembles assembly code in one pass It creates an intermediate file which acts as an input to two pass assembler
Two Pass Assembler As the name suggests two pass assembler does two passes over the source file. In first pass, all it does is looks for label definitions and introduces them in the symbol table (a dynamic table which includes the label name and address for each label in the source program). In the second pass, after the symbol table is complete, it does the actual assembly by translating the operations into machine codes and so on.

Example Codes of Assemble Code

Example of Assemble Code 2

Input Instructions



C Code For Two Pass Assembler

Other Related Posts

Any kind of questions and suggestions are welcome below in comments
Previous articleGATE Electronic Devices Multiple Choice Questions With Answers
Next articleWhat Is A Loader?


  1. There’s certainly a great deal to learn about this subject. I like all of the points you have made.


Please enter your comment!
Please enter your name here