Sunteți pe pagina 1din 23

Single pass & two pass assembler

ANALYSIS PHASE
1.Isolate the label, mnemonic opcode, operands
of the statement.
2.if a label is present,enter <symbol,LC content>
in the symbol table.
3.Check the validity of mnemonic opcode by
checking the mnemonic table.
4.Update LC by considering the opcode and the
operands.
Synthesis phase
1.Obtain the machine opcode corresponding to
mnemonic opcode from the mnemonic table.
2.Obtain the address of the symbols from the
symbol table.
3.Synthesize a machine instruction or the
machine form of a constant.
Single pass assembler

1. Analysis and synthesis done in one pass.


2. Pblm. Of forward reference.-a reference to
the entity which precedes its definition in the
program.

This can be tackled by ‘Backpatching’ (by using


TII).
1.The operand field of an instruction containing a
forward reference is left blank initially.
2.The entry <inst. Address, symbol> will be
entered into TII(Table of Incomplete Istructions)
3.By the time END stmt. Is encountered, symbol
table contains the address of every symbols in
the source code and TII.
The assembler would process each entry in TII
one by one .
• Single Pass Assembler
• A single pass assembler scans the program
only once and creates the equivalent binary
program. The assembler substitute all of the
symbolic instruction with machine code in one
pass.
• Advantages
Every source statement needs to be processed
once.
• Demerit
Pblm. Of forward reference , should be
tackled by ‘Backpatching’
• A two pass assembler does two passes over
the source file ( the second pass can be over a
file generated in the first pass ).
• In the first pass all it does is looks for label
definitions and introduces them in the symbol
table.
• In the second pass, after the symbol table is
complete, it does the actual assembly by
translating the operations and so on.
Two Pass Assembler
• Tasks performed by the passes of two-pass assembler are as
follows:
Pass I: -
• Separate the symbol, mnemonic opcode and operand fields.
• Determine the storage-required for every assembly language
statement and update the location counter.
• Build the symbol table and the literal table.
• Construct the intermediate code for every assembly language
statement.
Pass II: -
• Synthesize the target code by processing the intermediate
code generated during Pass 1
• Data structures required for pass I:
• 1. Source file containing assembly program.
• 2. OPTAB: A table of mnemonic op-codes and related
information. It has the following fields
• Mnemonic
• : Such as ADD, END, DC
• TYPE
• : IS for imperative, DL for declarative and AD for Assembler
directive
• OP- code
• : Operation code indicating the operation to be performed.
• Length
• : Length of instruction required for Location Counter
Processing
A Simple Two Pass Assembler
Implementation
Source READ (Label, opcode, operand)
program

Pass 1 Pass 2 Object


codes

OPTAB SYMTAB
SYMTAB

Mnemonic and Label and address Label and address


opcode mappings mappings enter mappings are referenced
are referenced from here from here
here
2pass assembler-Pass 1 algorithm
Continued…
Second pass-algorithm
Continued….
Intermediate code
Continued…

S-ar putea să vă placă și