Two Pass Assembler

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

GOVERNMENT ENGINEERING COLLEGE,MODASA

PASS - II OF TWO PASS ASSEMBLER


SUBJECT : System Progamming
Academic Year:
2017-2018

PREPARED BY : GUIDED BY :
MALVADKAR ABHISHEK(150160116046) RINKAL J. PRAJAPATI
INTRODUCTION

A two pass assembler tries to compute the value of each


expression as it encounters it, in two passes called "first" and
"second" passes.
Pass – I performs analysis of the source program and
synthesize of the intermediate representation.
While Pass – II processes the intermediate representation to
synthesize the target program.
FUNCTIONS

• Translate opcode and symbolic operands.


• Generate data values defined by BYTE,WORD etc.
• Assemble directives will be processed.
• Write the object program and assembly listing.
Assembler Directives

• Basic Assembler Directives


1. START
2. END
• Advance Assembler Directives
3. ORIGIN
4. EQU
5. LTORG
Algorithm
Step 1: code_area_address:= address of code_area;
Pooltab_ptr:=1;
LC:=0;
Step 2:while the next statement is not an END statement.
(a) clear machine_code_buffer;
(b) If an LTORG statement
(i)If POOLTAB[pooltab_ptr].#literals>0 then
process literals in the enteries LITTAB[ POOLTAB[pooltab_ptr.first]…
LITTAB [POOLTAB[pooltab_ptr+1]-1]
similar to processing of constants in a DC stmt.
(ii) size:= size of memory area required for literals;
(iii) pooltab_ptr:=pooltab_ptr+1;
(c) If a START or ORIGIN statement
(i) LC:= value specified in operand field;
(ii) size:=0;
(d) If a declaration statement
Algorithm ( cont..)
(i) IF a DC statement then
Assemble the constant in machine_code_buffer.
(ii) size:= size of the memory area required by the declaration stmt.
(e) If an Imperative statement then
i. Get address of the operand from its entry in SYMTAB or LITTAB,as
the case may be.
ii. Assemble the instruction in machine_code_buffer.
iii. Size:= size of the instruction;
(f) If Size!=0 then
iv. Move contents of machine_code_buffer to the memory word with the
address code_area_address+<LC>;
v. LC:= LC+size;
Step 3: (Processing of the END statement)
(a) Perform actions (i)-(ii) of Step 2(b).
(b) Perform actions (i)-(ii) of Step 2(f).
(c) Write code area into the output file.
Assembly Language Program

Label Mnemonic Operand1 Operand2


- START 101 -
- READ A -
- READ B -
- MOVER BREG A
- MULT BREG B
- MOVEM BREG D
- STOP - -
A DS 1 -
B DS 1 -
D DS 1 -
- END - -
• Assembly Language Program (ALP) Pass – I uses following
Data Structure.

– OPTAB :A table of mnemonic opcodes and related


information.
– SYMTAB :A table of Symbol.
– LITTAB :A table of literals used in the program.
– POOLTAB :A table of information concerning literals
pools.
– Intermediate code representation generated by Pass I
– Output file containing Target code / error listing at Pass II.
OPTAB
OPCODE MNEMONIC CLASS
SYMTAB
00 STOP IS SYMBOL ADDRESS VALUE/LENGTH
01 ADD IS
A 107 1
02 SUB IS
B 108 1
03 MUL IS
D 109 1
04 MOVER IS
05 MOVEM IS
06 COMP IS LITTAB
07 BC IS
LITERAL ADDRESS
08 DIV IS
09 READ IS
10 PRINT IS
01 DC DL
POOLTAB
02 DS DL
01 START AD FIRST #LITERALS

02 END AD 1 0
03 ORIGIN AD
04 EQU AD
05 LTORG AD
PASS – I

• Intermediate Code is generated after Pass – I as given below :


Mnemonic Opcode Operand Operand Class, Code
(AD,01)
(IS,09) (S,0)
(IS,09) (S,1)
(IS,05) 2 (S,0)
(IS,03) 2 (S,1)
(IS,04) 2 (S,2)
(IS,00)
(DL,02)
(DL,02)
(DL,02)
(AD,02)
Pass –II

• Machine code is generated after Pass –II


Address Machine Code Operand Object Code
000 01 0 101
101 09 0 107
102 09 0 108
103 05 2 107
104 03 2 108
105 04 2 109
106 00 0 000
107 Memory Allocate to A
108 Memory Allocate to B
109 Memory Allocate to C
110 02 0 000
Difference between variant –I & variant -II

Variant –I Variant- II
1. If operand –II is a symbol it 1. If it is a operand –II is a
is converted in a symbol then it is not
form(symbol table entry no.) converted & put as it is as a
symbol.

2. Pass-I requires separate data 2. Symbols are putted as it is


structure to handle forward so there is no need to
reference of the symbol. handle problem of forward
reference.
3. pass –I algorithm is complex 3. pass-I Algorithm code is
& coding is heavy. light as well as very easy to
implement
Th a n k
You

You might also like