Design of 2 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.
Then the assembler processes to the next instruction. In this way, the entire machine code program is created
Read about: leanandfit
What is the difference between one pass and two pass assembler?
What is a single pass assembler?
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
Why do we need a two pass assembler?
As explained, 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
Topics covered:How 2 pass assembler works?
2 pass assembler algorithm.
2 pass assembler Design.
2 pass assembler program
Agenda
Introduction
Advanced Assembler Directives
- ORIGIN
- EQU
- LT ORG
Data Structure used in Pass I
- OPTAB
- SYMTAB
- LITTAB
- POOLTAB
Intermediate code
Declaration and Assembler Directive Processing
Pass II of the Assembler
- 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
- Read from input line
- LABEL, OPCODE, OPERAND
Two Pass Assembler |
Design of 2 - Pass Assembler
Pass 1:
- Separate the Symbol, Mnemonic opcode and operand fields
- Build the symbol table
- Perform LC Processing
- Construct Intermediate Representation
Pass 2
Synthesize the target program
Advanced Assembler Directives
- ORIGIN
- EQU
ORIGIN
Syntax:
ORIGIN < Address Specification>
ORIGIN < Address Specification>
EQU
Syntax:
<Symbol> EQU <Address Specification>
E.g. MAXLEN EQU 4096
Syntax:
<Symbol> EQU <Address Specification>
E.g. MAXLEN EQU 4096
Pass I of Assembler
- Pass I Uses following Data Structures
- OPTAB
- SYMTAB
- LITTAB
- POOLTAB
OPTAB
SYMTAB: Symbol Table
LITTAB: Table of Literals used in program
POOLTAB: A table of information concerning literal pool
Algorithm
The main reason why most assemblers use a 2-pass system is to address the problem of forward 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' 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.
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' 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.
Anykind of questions and suggestions are welcome below in comments
0 comments:
Post a Comment