FIRST PASS OF ASSEMBLER
ACTIVE LEARNING
ASSIGNMENT
FOR
THE SUBJECT
“SYSTEMS
PROGRAMMING”
PREPARED BY:
HEMANT H. CHETWANI
(130410107010 – TY CE-II)
What is Assembler ?
An Assembler is a language processor that converts
an assembly language program into a machine
language program.
To perform this conversion, it has to analyze the
source program, determine which symbols used in the
program correspond to which data or instruction, and
use this information while synthesizing a target
program. The organization of an assembler shows how
it structures the various analysis and synthesis tasks.
Types of Assembler (According to it’s Pass structure)
2.
Two pass
assembler
1.
Single Pass
Assembler
1.
Single Pass
Assembler
ALP is converted into a target program on a
statement by statement basis. Analysis &
synthesis both tasks are done within a single pass
only…
Two pass
assembler
1st PASS
Analysis Phase
2nd PASS
Synthesis Phase
Tasks of Analysis Phase
1. Separate label,
opcode & operand
2. Build the symbol
table
3. Perform LC
processing
4. Construct IC
Analysis
Tasks of Synthesis phase
1. Obtain the machine
opcode corresponding
to the mnemonic
2. Obtain the address
of a memory operand
from symbol table
3. Synthesize the
machine instruction
Synthesis
Design of a two pass assembler
1. Separate label,
opcode & operand
2. Builds the symbol
table
3. Perform LC
processing
4. Construct
Intermediate Code
1st pass
Generates Target
Program (Machine
Code)
2nd Pass
Pass 1
Pass 2
Source
Program
Target
Program
Data Structures
Intermediate
Code
1st Pass
Constructs
Intermediate
Code
1.
Data
structures
(symbol table)
2.
Intermediate
form of
source
program
Data Structures
• Table of mnemonic
Opcodes and related infoOPTAB
• Contains symbol name,
addressSYMTAB
• Table of literals used in
the programLITTAB
• Table of information
concerning literal poolsPOOLTAB
Opcode Table
Class
IS DS AD
Mnemonic info
(Machine Opcode, Inst Length) Mnemonic info
ID of a routine
Symbol Table
Literal Table
Pool Table
Intermediate Code Format
Example
MOVER AREG, A
Which information do we need to convert
this instruction in to its equivalent
intermediate code???
1.
CLASSES
2.
CODES
(Statement Class, Opcode)
Statement
Class
IS
(Imperative stmt)
DS
(Declarative stmt)
AD
(Assembler
Directives)
(Operand Class, Code)
Operand
Class
C
(Constant)
L
(Literal)
S
(Symbol)
Classes & Opcodes
MOVER AREG,A
(IS, 04) (1)(S, 01)
Example Program
PASS-1 Algorithm
Example
START 200
X DS 4
L1 MOVER AREG,Y
SUB AREG,Z
MOVEM AREG,W
W EQU X+2
L2 PRINT W
ORIGIN X-5
Z DC ‘9’
ORIGIN L2+1
STOP
Y DC ‘7’
END
LC
200
204
205
206
207
195
208
209
Example
START 200
X DS 4
L1 MOVER AREG,Y
SUB AREG,Z
MOVEM AREG,W
W EQU X+2
L2 PRINT W
ORIGIN X-5
Z DC ‘9’
ORIGIN L2+1
STOP
Y DC ‘7’
END
(AD,01)(C,200)
(DL,02)(C,04)
(IS,04)(1)(S,01)
(IS,02)(1)(S,02)
(IS,05)(1)(S,03)
(AD,04)
(IS,10)(S,03)
(AD,03)
(DL,01)(L,01)
(AD,03)
(AD,00)
(DL,01)(L,02)
(AD,02)
SYMTAB
SYMBOL ADDRESS LENGTH
X 200 4
L1 204 1
W 202 1
L2 207 1
Z 195 1
Y 209 1
LIKEWISE...
WE CAN GENERATE ALL THE TABLES THAT WE NEED
USING FIRST PASS OF ASSEMBLER
First pass of assembler

First pass of assembler