ASSEMBLERS
Prof. S.J. Soni, SPCE, Visnagar
Design Specifications
Identify the information necessary to perform a task
Design a suitable data structure to record the
information
Determine the processing necessary to obtain and
maintain the information
Determine the processing necessary to perform the
task
Synthesis Phase
MOVER BREG, ONE
Address
of the memory word with which name ONE is
associated (depends on source program, so it must be
made available by the analysis phase)
Machine op codes corresponding to the mnemonic
MOVER (not depends on source program, it depends on
the assembly language)
Use two data structures:
Symbol
Table (name, address) build by analysis phase
Mnemonic Table (mnemonic, opcode, length)
Analysis Phase
The primary function is of building of the symbol
table.
Concept of Memory Allocation
To implement memory allocation a data structure
called location counter (LC) is used.
The LC is always made to contain the address of the
next memory word in the target program.
It is initialized to the constant specified in the START
statement.
To update the contents of LC, analysis phase needs
to know lengths of different instructions.
Data structures of the assembler
SP
Mnemonic
Opcode
Length
ADD
01
SUB
02
Analysis
Phase
Mnemonic Table
Synthesis
Phase
Symbol
Address
AGAIN
104
113
Symbol Table
TP
Pass Structure of Assembler
Two Pass Translation
It
can handle forward references easily.
LC processing is performed in the first pass and symbol
defined in the program are entered into the symbol
table.
The second pass synthesizes the target form using the
address information found in the symbol table.
In effect, the first pass performs analysis of the source
program while the second pass performs synthesis of
the target program.
Two pass assembly
Data Structures
SP
TP
Pass I
Pass II
Intermediate Code
Pass Structure of Assembler
Single Pass Translation
LC
processing and construction of the symbol table
proceeds as in two pass translation.
The problem of forward references is tacked using a
process called backpatching
The operand field of an instruction containing a
forward reference is left blank initially. The address of
the forward referenced symbol is put into this field
when its definition is encountered.
MOVER BREG, ONE
[ONE is forward reference]
Table of Incomplete Instruction (TII)
Advanced Assembler Directives
ORIGIN
ORIGIN
<address spec>
Where <address spec> is an <operand spec> or
<constant>
This directive indicates that LC should be set to the
address given by <address spec>.
It is useful when the target program does not consist of
consecutive memory words.
Advanced Assembler Directives
EQU
<symbol>
EQU <address spec>
Where <address spec> is an <operand spec> or
<constant>
It defines the symbol to represent <address spec>.
LTORG
It
permits a programmer to specify where literals
should be placed.
By default, assembler places it after the END statement
Literals
At every LTORG statement, as also at the END statement, the
assembler allocates memory to the literals of a literal pool.
The pool contains all literals used in the program since the start
of the program or since the last LTORG statement.
Design of a Two Pass Assembler
Tasks performed by the passes of a two pass
assembler are as follows:
Pass I
Separate
the symbol, mnemonic opcode, operand fields
Build the symbol table
Perform LC processing
Construct intermediate representation
Pass II
Synthesis
the target program
Pass I of an assembler
It uses the following data structures:
OPTAB
A table of mnemonic opcodes and related
information
SYMTAB Symbol Table
LITTAB A table of literals used in the program
Data Structures of assembler Pass I
Algorithm- Assembler First Pass
Intermediate code for Imperative Statements
Variant I and Variant II
Variant I
Variant II
Comparison of the variants
Comparison of the variants
Comparison of the variants
Pass II of an assembler
Pass II of an assembler
Tables
Pass II of an assembler
Source Program and Intermediate Code