The document discusses the design and implementation of the second pass of a two-pass assembler. It explains that a two-pass assembler handles forward references easily by building a symbol table in the first pass and then using it to synthesize the target program in the second pass. The first pass constructs an intermediate representation using the symbol table, which the second pass then processes to generate the target code. The algorithm for the second pass is described, which involves processing the intermediate representation and writing the target code to an output file.
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
Design & implementation of pass 2 of two pass assembler
1. System Programming
Walchand Institute of Technology
Aim:
Design & implementation of
Theory:
Two pass translation
Two pass translation of an assembly language program can handle forward
references easily. LC processing is performed in the first pass and symbols 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
second pass performs synthesis of the target program. The first pass constructs an
intermediate representation of the source program for use by the second pass as
shown in figure. This repre
structures, e.g. the symbol table, and a processed form of the source program. The
latter component is called intermediate code.
Figure: Overview of two pass assembly
Tasks performed by the passes of a two
• Pass I:
1. Separate the symbol, mnemonic, opcode and operand.
Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur
HANDOUT#07
Design & implementation of pass 2 of two pass assembler
Two pass translation of an assembly language program can handle forward
references easily. LC processing is performed in the first pass and symbols defined
in the program are entered into the symbol table. The second pass synthesizes the
the address information found in the symbol table. In effect, the
pass performs synthesis of the target program. The first pass constructs an
intermediate representation of the source program for use by the second pass as
shown in figure. This representation consists of two main components
structures, e.g. the symbol table, and a processed form of the source program. The
latter component is called intermediate code.
Figure: Overview of two pass assembly
Tasks performed by the passes of a two pass assembler are as follows:
Separate the symbol, mnemonic, opcode and operand.
Sunita M. Dol, CSE Dept
Page 1
Two pass translation of an assembly language program can handle forward
references easily. LC processing is performed in the first pass and symbols defined
in the program are entered into the symbol table. The second pass synthesizes the
the address information found in the symbol table. In effect, the
pass performs synthesis of the target program. The first pass constructs an
intermediate representation of the source program for use by the second pass as
sentation consists of two main components—data
structures, e.g. the symbol table, and a processed form of the source program. The
pass assembler are as follows:
Separate the symbol, mnemonic, opcode and operand.
2. System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 2
2. Build Symbol Table.
3. Perform LC Processing.
4. Construct Intermediate Representation.
• Pass II:
1. Process IR to synthesize the target program.
Pass I performs analysis of the source program and the synthesis of the
intermediate representation while Pass II processes the intermediate representation
to synthesize the target program.
Following algorithm is the algorithm for assembler Pass II
Algorithm for Pass II
1. code_area_address := address of code area
pooltable_ptr := 1
location_counter := 0
2. While next statement is not an end statement then
a. Clear machine_code_buffer
b. If an LTORG statement then
i. Process literals in LITTAB[POOLTAB[pooltable_ptr]]……..
LITTAB[POOLTAB[pooltable_ptr + 1] -1 similarly
processing of constants in a DC statement i.e. assemble the
literals in machine_code_buffer.
ii. size := size of memory area required for literals
iii. pooltable_ptr := polltable_ptr +1
c. if a START or ORIGIN statement then
i. location_counter := value specified in operand field
ii. size := 0
d. If a declaration statement then
i. If a DC statement then
Assemble the constant in machine_code_buffer
ii. size := size of memory area required by DC or DS
e. If an imperative statement then
3. System Programming
Walchand Institute of Technology
i. Get the
ii. Assemble instruction in machine_code_buffer
iii. size := size of instruction
f. If size <> 0 then
i. Move the contents of machine_code_buffer to the address
code_area_address + location_counter
ii. location_counter :=
3. Processing end statement
a. Perform steps 2(b) and 2(f)
b. Write code_area into output file
Figure: Example of converting source program to machine language
Input:
0 (AD, 01) (C, 200)
Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur
Get the operand address from SYMTAB or LITTAB
Assemble instruction in machine_code_buffer
size := size of instruction
If size <> 0 then
Move the contents of machine_code_buffer to the address
code_area_address + location_counter
location_counter := location_counter +size
Processing end statement
Perform steps 2(b) and 2(f)
Write code_area into output file
Figure: Example of converting source program to machine language
(AD, 01) (C, 200)
Sunita M. Dol, CSE Dept
Page 3
operand address from SYMTAB or LITTAB
Assemble instruction in machine_code_buffer
Move the contents of machine_code_buffer to the address
location_counter +size
Figure: Example of converting source program to machine language
6. System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 6
214) 00 0 001
Conclusion:
The second pass or Pass-II synthesizes the target form using the address
information found in the symbol table.
The second pass performs synthesis of the target program.
Pass I performs analysis of the source program and the synthesis of the
intermediate representation while Pass II processes the intermediate
representation to synthesize the target program.
Thus the Pass-II of two pass assembler is implemented in C-language