You are on page 1of 36

Assembler

Assembly Language
An Assembly language is the lowest level
programming language for a computer and
machine dependent .
Assembly language provides the following
three basic features which make
programming a lot easier than in machine
language.
1. Mnemonic Operation Codes.
2. Symbolic Operand Specification.
3. Declaration of data/storage area:

Assembly Language
1.Mnemonic Operation Codes.
Instead of using numeric opcodes (i.e. pattern of 0
& 1), mnemonics are used e.g. ADD, SUB etc.
2. Symbolic Operand Specification.
Symbolic names can be associated with data or
instructions . Operands can be specified in the
form of symbolic references, rather than as
machine addresses of data or instructions.

Assembly Language
3. Declaration of data/storage area:
Data can declared using the decimal
notation. This avoids the manual conversion
of constants into their internal machine
representation.
e.g 5 into (0101)2
10.5 into (41A80000)16

Assembly Language
Assembly language consist of three kinds of
statements
1. Imperative statements
Imperative assembly language statements
indicates actions to be performed during the
execution of the assembled program. Hence
each imperative statement translates into
machine instruction.
General Instruction format is
Label Opcode Operand [,Operand]

Assembly Language- Imperative


statements
Following are the some instructions with opcode:
Instructi
on
Opcode

Assembly
Mnemonic

Remark

00

STOP

Stops program.

01

ADD

02

SUB

First Operand is assumed to be in the


accumulator.

03

MULT

04

LOAD

Load into accumulator

05

STORE

Store accumulator into storage location.

06

TRANS

Transfer control to address mentioned.

07

TRIM

Transfer only if accumulator < 0

08

DIV

Divide accumulator by storage location contents.

09

READ

Read a card into storage location

10

PRINT

Print storage location contents.

Assembly Language- Imperative


statements
Instructi
on
Opcode

Assembly
Mnemonic

Remark

11

LIR

Load index register with last three digits of


storage operand.

12

IIR

Increment index register with last three digits of


storage operand.

13

LOOP

Decrement index register. If new contents >0


then same as TRANS.

Assembly Language-Declarative
statements

2. Declarative statements:
A declarative statement assembly
language statement declares constants or
storage areas in a program.
e.g.
i) A
DS 1
ii) G
DS
200
These statements simply declares a storage
area of 1 word and block of 200 words
respectively.
Constants are declared using Declare
Constant (DC) statement.

Assembly Language-Assembler
Directives

3. Assembler Directives:
Assembler Directives neither represent
machine instructions instead of that they
direct the assembler to take certain actions
during the process of assembling a
program.
e.g.
START 100
This statement indicates that the first word
of the object program generated by the
assembler should be placed in the memory
location with address 100
END

Assembly Language-Program

The Process of Translation


The general model for the translation process can be
represented as follows:
Analysis of
Synthesis of
Translation from
Source Source Text
+
Source Text
= to
Target Text
Analysis Phase:

In the analysis phase , we are concerned with


the determination of meaning of a source
language text, for that we should know the
grammar of source language . Further we should
also know how to determine the meaning of a
statement once its grammatical structure

The Process of Translation


Synthesis Phase:
In the synthesis phase , the source language
statements are replaced by target language
statements.

General Design Procedure of


Assembler
Following fig. shows the general procedure for
translation of assembly program

Assembl
y
Langua
ge
Program

Analysi
s
Phase

Which consist of two phases:

1. Analysis Phase.
2. Synthesis Phase.

Synthe
sis
Phase

Equivale
nt Target
Code

General Design Procedure of


Assembler
1. Analysis Phase.
In this phase following functions are
performed.
i. Isolate the label, mnemonic operation code
and operand fields of a statement
ii. Enter the symbol found in label field (if any)
and its address into Symbol Table.
iii. Validate the mnemonic operation code by
looking it up in the Mnemonic Table.
iv. Determine the storage requirements of the
statement by considering the mnemonic
operation code and operand fields of the
statement. Calculate the address of the first

General Design Procedure of


Assembler
2. Synthesis Phase.
In this phase following functions are
performed.
i. Obtain the machine operation code
corresponding to the mnemonic operation
code by searching the Mnemonic table.
ii. Obtain address of the operand from Symbol
table.
iii. Synthesis the machine instruction or the
machine form of the constant, as the case
may be.

Some Assembler Directives


1. ORIGIN
This directive sets the location counter to
the given address.
e.g. ORIGIN 200
sets the location counter(LC) value to 200.

2. EQU
The EQU statement simply defines a new
symbol and gives it the value indicated by
operand expressions.
e.g. FIRTST EQU LAST

Some Assembler Directives


3. LTORG
While assembling, a reference to literal, the
following care should be taken:
i ) Allocation of machine location to contain the
value of the literal during execution and
ii) Use of the address of this location as the
operand address in the statement referencing
the literal.
At every LTORG , statement assembler allocates
all literals used in the program .

Some Assembler Directives

Types of Assembler
1. Multi-pass Assembler
2. Single-pass Assembler
An Assembler pass is one complete scan of the
source program input an assembler.

1. Single-pass Assembler:
- Single-pass assembler have the advantage
that every source statement processed only
once.

Single pass assembler would face a problem


while translating forward references.
This problem can be solved as below:

Types of Assembler
-

Instructions containing forward references


can be left incomplete until address of the
referenced symbol becomes known. These
incomplete instructions are placed into a
table called as Table of Incomplete

Instructions (TII).
-

On encountering its definition, its address


can be filled into that instruction.

Types of Assembler
2. Multi-pass Assembler
- Multi pass assemble resolves the problem of
forward reference by using more than one
passes.
- In first pass analysis is takes place in which
LC processing is performed and symbols
defined in the program are entered into the
symbol table.
- During the second pass, statements are
processed or synthesized
to
generate
machine
Equivale
Assembly
Intermediat
Pass II
Pass
instructions.
Language
nt Target
e Code
I
Program
Code

Data Structures Used in Pass-I of an


Assembler

Following Data Structures are used in Pass-I


of an Assembler:
1. OPTAB (Opcode Table)
2. SYMTAB ( Symbol Table)
3. LITTAB (Literal Table)

Data Structures Used in Pass-I of an


Assembler

1. OPTAB

(Opcode Table)

Mnemon Class
ic
Opcode

Machine
Opcode/
Routine ID

Lengt
h

LOAD

1 (Imperative)

04

DS

2 (Declarative)

R#7

START

3 ( Directive)

R#11

STORE

1 (Imperative)

05

Data Structures Used in Pass-I of an


Assembler

2. SYMTAB

(Symbol Table)

Symbol

Address

Length

Other
Inform
ation

110

Data Structures Used in Pass-I of an


Assembler

3. LITTAB

(Literal Table)

Literal

Address

=5

110

=1

112

=1

120

POOL TAB

Next Free entry


Current Pool Pointer

Design of Two Pass Assembler


Source
program

Intermediate
file

Pass 1
OPTAB

SYMTAB

Pass 2

Object
codes

SYMTAB

Pass-I
-Separate the symbol, mnemonic opcode and operand fields.
-Determine the storage required for every assembly language
statement and update the location counter.
- Build the symbol table.
- Construct intermediate code.

Pass-II
- Synthesize the target code by processing intermediate code
generated during Pass-I

Pass-I of an Assembler

LARGEB

START
READ
READ
LOAD
SUB
TRIM
PRINT
STOP
PRINT
STOP
END
FIRST DS
A
DS
B
DS

100
A
B
A
A
LARGEB
A
B
1
1
1

Intermediate Code

Pass-II of an
Assembler

Hashing or Random Entry Search


To put elements in the order into the table
(SYMTAB,LITTAB etc.) slows down the process.
A considerable improvement can be achieve by
inserting element in random way.
The random entry- number K is generated from
the key by using function h(k) called as
hashing function.
There is probability that same random number
may be generated for two or more keys such
condition is called as collision.
Hashing function should be fast and
reduced collision

Hashing or Random Entry Search


Two popular hashing functions are as below:
1. Multiplicative Method:
e=
h(ki )
= (a . ki + b) mod m
where ki is the symbol(key) and (m1) is the maximum integer number which the
computer can store.
2. Divisive method:
In divisive methods, the symbol (key) is
divided by N, (N is table size), and the entry
number is called as

Collision Handling Methods


1. Rehashing technique:
In this technique ,when a collision occurs, a
new entry number is obtained for the colliding
symbol by applying another hashing function.
Thus , if collision occurs on applying the
hashing function hi (k), a function hi +1(k) is
applied and a probe (entry) is made at hi +1(k) th
entry in the table .

Collision Handling Methods


2. Overflow chaining technique:
In this technique ,all the symbols (keys) which
encounter a collision at first hash are store in a
separate table called as overflow table .
All overflow table entries belonging to the same
hash table entry are chained together.
A pointer in the hash table points to be the first of
these overflow
entry.
Symbol
Pointer
Symbol Pointer
COUNT

NEXT1

MAX

TEMP

VALUE

BIG

Hash Table

Overflow Table

Thank You

You might also like