Sie sind auf Seite 1von 38

Assembler

Assembler
 An Assembler is a program that accepts as input an assembly language
program and produces its machine language along with information for the
loader

Assembler
Assembly
Data bases Machine Language and
language
other information for the
program
loader
\

Collected By: pallavi


General Design Procedure

 Specify the problem


 specify Data Structures
 Define format of DS
 Specify algorithms
 Look for modularity
 Repeat 1 through 5 on modules
Statement of the Problem

1. We read the start instruction and note that it is a pseudo op instruction giving john as
the name of this program , the assembler must pass the name to the loader.

2. The next is the using pseudo op instruction. This tells the assembler that register 15 is
the base register and at execution time will contain the address of the first instruction
of the program.

3. There is no BALR instruction so this program was presumably called by another


program that left the address of the first instruction in register 15.
ANALYSIS PHASE:-

In this phase, it scans source code to collect relevant information


for assembly. Here LC is processed, Symbol table, Literal table are
maintained and
At the end, the Intermediate Representation (IR) of the source
code is constructed to be used in second Pass.

IR: contains main two components:


• Data Structures (Symbol Table & Literal table).
• Intermediate Code (Processed form of Source Code)

SYNTHESIS PHASE:
This phase uses the data structures & IR prepared by the Pass I to
produce target Code.
EXAMPLE
 Consider the assembly statement:-
MOVER BREG , ONE
for this, machine instruction:-

1. Address of the memory word with which ONE is associated


2. Machine operation code corresponding to mnemonic MOVER

The first item of information depends of source program and is


made avail by the ANALYSIS PHASE.

The second item depends on assembly language, hence


synthesis phase can determine it.
Data Structures Used

 SYMTAB
 LITTAB
 MOT
 POT
 LC
 POOLTAB
SYMTAB

 Used to contain all the symbols


 Inlcudes variables, procedures, constants
and labels
 Contains name of symbol, address and its
value
 Eg: N DS 1
 Where N is the symbol, VALUE is 1 and
location is 21
LITTAB
 Contains information about all Literals
 Includes name of literal and its location
 Various literals are allocated addresses when
LTORG instruction encountered.
 If LTORG is not present, then literals are
allocated addresses when END encountered.
 E.g Literal Address
 =‘2’ 212
 =‘1’ 213
MOT
 It is a static or fixed table in nature, its contents does
not change during the lifetime of a assembler.
 It contains name of the mnemonic, its binary name
and length.
 Mnemonic is the key for searching MOT and its value
is the binary code that is used for generation of
machine code.
 E.G. Mnemonic Opcode Length
 ADD 01 1
 SUB 02 1
POT
 To include assembler directives.
 Mnemonic Class
 MOVER IS
 DS DS
 START AD
Where IS=> imperative statements
DS=>Declarative statements
AD=> Assembler Directives
LC

 Keep track of each instruction’s location


 Used to perform memory allocation
 E.g.
 START 501

Collected By: pallavi


Two Pass Translation Structure

 Pass: Meaning of Pass is that processing of each


& every statement in source code for assembly.

 To Translate the source code the code has to be


scanned twice,

• Once during Analysis Phase


• Once during Synthesis Phase

Collected By: pallavi


Specifically the assembler must do the following:
1.Generate Instructions
A) Evaluate mnemonic in the operation field to produce its machine code.
B) Evaluate Subfields- Find the value of each symbol, process, literals and assign
addresses.
2. Process Pseudo ops

Collected By: pallavi


Data Structure
Pass 1:
1. Input Source Program

2. A location Counter (LC) used to keep track of each instruction’s location

3. A table, The machine operation table (MOT) that indicates the


symbolic mnemonic for each instruction and its length.

4. Pseudo Operation table (POT), indicates the symbolic mnemonic and


action to be taken for each pseudo op in pass 1.

5. The symbol table (ST), used to store each label and its corresponding
value.

6. The Literal Table (LT), used to store each literal encountered and its
corresponding assigned location.
Collected By: pallavi
Pass Structures of Assembler
 Single pass assembler
 Two pass assembler
 Single pass
 Scans the input file only once
 Generally faster than two pass assembler

 Constructs SYMTAB,LITTAB,MOT AND POT

 Performs LC processing

 Main problem encountered here is FORWARD REF


 It is a reference to an entity that precedes its definition in the
program. Usage of symbols before its definition appeared in the
program.

Collected By: pallavi


 Problem of Forward Reference has been
handled by single pass assembler using
BACKPATCHING.
 It is a process in which an operand field containing
forward reference is left blank initially and its
address is put when its definition encounters in the
program.
 In order to perform back patching single pass
assembler requires another DS called
TII(Table of incomplete instruction)
 It contains all those instructions that contain fwd
ref.
Collected By: pallavi
Collected By: pallavi
Two pass assembler
 It scans the input assembly language program
twice.

 It generates the target program using the


address information from symbol table and
literal table

Collected By: pallavi


Purpose of PASS 1

 To assign a location to each instruction and

 Data defining pseudo instruction, and

 Thus to define values for symbols appearing in


the label fields of the source program.

Collected By: pallavi


Pass1 only deals with those pseudo ops that define symbols or effect the location
counter. Using and drop do neither so save them for pass 2
Look for Modularity

Collected By: pallavi


Algorithm
 Pass 1: Define Symbols
1) The purpose of the first pass is to assign a location to each instruction and data
defining pseudo-instruction, and thus to define values for symbols appearing in the
label fields of the source program.

2) Initially the LC is set to the first location of the program(relative address 0).

3) Then a source statement is read.

4) the op-code field is examined to determine if it is a pseudo-op, if it is not the


table of machine op-codes is searched to find a match for the source statement’s op-
code field.

Collected By: pallavi


PASS 2: Generate Code

 After all the symbols have been defined by pass1, it is possible it is possible
to finish the assembly by processing each card and determining values to
its operation code and its operand field.

 In addition pass2 must structure the generated code in to appropriate


format for later processing by the loader and print an assembly listing
containing the original source and the hexadecimal equivalent of the bytes
generated.

Collected By: pallavi


Pass 2

Collected By: pallavi


Collected By: pallavi
Collected By: pallavi
Collected By: pallavi
Specify Data Structure

Pass 1 Database:

 Input Source Program


 Location Counter
 MOT- Table indicates the symbols for each instruction and its length (2,4
or 6 bytes)
 POT-Indicates symbolic mnemonic and action to be taken for each
pseudo-op.
 LT-Indicates each encountered literal and its assigned location.
 Copy of input to be used later by pass 2.

Collected By: pallavi


Specify DATA Structure
Pass 2 Database:
 Copy of Source Program Input to Pass 2.
 Location Counter
 MOT- 1.symbolic mnemonic,2.length,3.binary machine opcode, 4.format
 POT-Indicates symbolic mnemonic and action to be taken for each
pseudo-op.
 ST-Indicates each label & its corresponding value .
 BT-which register are currently used as base register
 Workspace INST- holds each instruction.
 Workspace PRINT LINE- used to produce a printed listing.
 Work Space PUNCH CARD- Converts assembly instruction in loader
needed format
 Output Deck of assembled instructions (in format needed by loader)

Collected By: pallavi


Collected By: pallavi
Collected By: pallavi
Collected By: pallavi
Collected By: pallavi
Collected By: pallavi

Das könnte Ihnen auch gefallen