You are on page 1of 86

MODULE 1

INTRODUCTION AND ASSEMBLER


A program must be retranslated following modifications.
Forward reference
- A forward reference of a program entity is a reference to the entity which
precedes its definition in the program.
Example:
percent profit := (profit * 100) / cost price);
……..

long profit;
LP Pass:
- A LP pass is the processing of every statement in a source program , or its
equivalent representation, to perform a language processing function
(a set of LP functions).
- Process a program in 2 passes:

Pass I : Perform analysis of the source program and note relevant information.
Pass II : Perform synthesis of target program.
Intermediate Representation:

- An IR is a representation of a source program which reflects the effect of


some but not all, analysis synthesis task performed during LP.

- SP Front End Back End TP

- IR

- Fig. Two pass schematic for language processing.


A := b + I ;
A simple Assembly Scheme
Design specification of an assembler :
- We use four step of approach to develop a design specification for an assembler:

1) Identify the information necessary to perform a task.


2) Design a suitable data structure to record the information.
3) Determine the processing necessary to obtain and maintain the information

For the Synthesis phase , consider the assembly statement


MOVER BREG, ONE

For this instruction we must have :


1) Address of the memory word with which name ONE is associated.
2) Machine operation code corresponding to the mnemonic MOVER.
Used two Data structures during synthesis phase
(1) Symbol Table, (2) Mnemonic Table

Analysis phase :

1. Isolate the label, mnemonic opcode and operand fields of a statement.


2. If label is present, enter the pair ( Symbol, <LC contents >) in a new entry in a symbol table .
3. Check validity of the mnemonic opcode through a look – up In the mnemonic table.
4. Perform LC processing that is update the value contained in LC by considering the opcode
and operands of the statement.
Synthesis phase :
1. Obtain the machine opcode corresponding to the mnemonic from the mnemonic
table.
2. Obtain address of a memory operand from the symbol table.
3. Synthesis the machine instruction or the machine form of a constant, as the case
may be.
Pass Structure of Assemblers
Single pass translation :
A single pass assembler scans the program only once and create the equivalent
binary program. The assembler substitute all of the symbolic instruction with machine code
in one pass.

Two pass translation :


Design of a two pass assembler

Pass I:
1. Separate the symbol, mnemonic opcode and operand fields.
2. Build the symbol table.
3. Perform LC processing.
4. Construct intermediate representation.
Pass II: START 200 LC
Synthesize the target program. MOVER BREG=‘4’ 200
LOOP MOVER AREG N 201
Advanced Assembler Directives : ADD BREG=‘2’ 202
1) ORIGIN ORIGIN LOOP + 5
ORIGIN <address spec>
NEXT BC ANY, LOOP 206
LTORG 207
1) LTORG ORIGIN NEXT + 3
N DC 5 209
2) EQU END 210
Basic format is : <symbol> EQU <address spec>
(Using EQU directive we are actually Literal Address
associating LHS label with the RHS =‘4’ 207
address, i.e “X is set to the address of Y”)
=‘2’ 208
Pass I Initializer

Modify LC
Read next
instr.

yes Process
END
IS Literals Pass II

Instr. yes
Insert label in
ORIGIN Has
IC label? symbol table

No
DL
Types of
instruction

LTORG
Data structure in pass I

1) Assembly program
2) Machine code opcode table (MOT)
3) Symbol table
4) Literal table
5) Pool table

A-C RG 01-03 ---


EQ,LT,GT, CC 01-06 ---
LE,GE,WE
ST LT POOL
Pass II
Source program
( Row Material )
in assembler

This is serving as a i/p

Pass I

IC
Data structure

Pass II
Furnished code
- Hence the grammar must be written such that reduction of * precedes the
reduction of + in a + b * c;

You might also like