Professional Documents
Culture Documents
Introduction
There are two main classes of programming languages: high level (e.g., C,
Pascal) and low level.
• Label
– symbolic labeling of an assembler address (command address at Machine level)
• Mnemomic
– Symbolic description of an operation
• Operands
– Contains of variables or addresse if necessary
• Comments
– ignored by assembler
– used by humans to document/understand programs
– tips for useful comments:
• avoid restating the obvious, as ‚decrement R1‛
• provide additional insight, as in ‚accumulate product in R6‛
Advantages of coding in assembly language are:
•Provides more control over handling particular hardware
components
•May generate smaller, more compact executable modules
•Often results in faster execution
Disadvantages:
•Not portable
•More complex
•Requires understanding of hardware details (interfaces)
DESIGN OF ASSEMBLER
Intermediate Object
Pass 1 Pass 2
file codes
SYMBOL
TABLE
First Pass:
•scan program file
•find all labels and calculate the corresponding addresses; this is
called the symbol table
Second Pass:
•convert instructions to machine language, using information from
symbol table
General Design Procedure of Two Pass
Assembler
1. Specify the problem
2. Specify data structures
3. Define format of data structures
4. Specify algorithm
5. Look for modularity [capability of one program to be
subdivided into independent programming units.]
6. Repeat 1 through 5 on modules.
STATEMENT OF PROBLEM
EX:
JOHN START 0
FOUR USING *, 15
FIVE L 1, FIVE
TEMP A 1, FOUR
ST 1, TEMP
DC F ‘4’
DC F ‘5’
DS 1F
END
Intermediate steps in assembling a program
FIRST PASS SECOND PASS
RELATIVE
ADDRESS MNEMONIC RELATIVE MNEMONIC
(LC) INSTRUCTION ADDRESS INSTRUCTION
JOHN START 0
USING 8, 15
L 1, FIVE 0 L 1, -(0,15) 0 L 1, 16(0,15)
A 1, FOUR 4 A 1, -(0,15) 4 A 1, 12(0,15)
ST 1, TEMP 8 ST 1, -(0,15) 8 ST 1, 20(0,15)
FOUR DC F '4' 12 4 12 4
FIVE DC F '5' 16 5 16 5
TEMP DS 1F 20 - 20 -
JOHN START 0
START is a pseudo–op, which indicates the beginning of the program.
JOHN is the name of the program which is passed on to the loader by the assembler.
0 indicates the relative address of this program starts at 0
USING *,15
USING is a pseudo–op, that tells the assembler that register 15 is used as the base
register, and at execution time will contain the address of the first instruction of the
program i.e., 0.
L 1, FIVE
Represents LOAD instruction which is of type RX.
Equivalent mnemonic instruction after pass 1 is
L 1, - (0,15)
Where:
- Represents offset
0 Represents Index Register
15 Represents Base Register
A 1, FOUR
Represents ADD instruction which is of type RX.
The offset(offset usually denotes the number of address locations added to a base
address in order to get to a specific absolute address) of the FOUR is not known at this
point therefore the equivalent mnemonic instructions after pass 1 is:
A 1, - (0, 15)
ST 1, TEMP
Stores the contents of register 1 to TEMP.
It is of RX type instruction
The offset of TEMP is not known therefore the equivalent mnemonic instructions after
pass 1 is:
ST 1, -(0, 15)
FOUR DC F ‘4’
DC is a pseudo–op which defines a constant value 4 for FOUR.
It is been stored at relative locations 12.
One full word is reserved for this constant, therefore location counter is incremented by 4
FIVE DC F ‘5’
TEMP DS 1F
DS is a pseudo op which defines storage space for TEMP.
One full word is reserved for TEMP at relative location 20.
The Second Pass evaluates the fields and generate, the codes. i.e., it goes through the
program and fills the offset values.
Specify the problem
Base Table
(BT)
Format of Data Structures
• Machine Operation Table
– The op-code is the key and it’s value is the binary op code
equivalent, which is used for use in generating machine code.
– The instruction length is stored for updating the location
counter.
– Instruction format is use in forming the m/c language
equivalent
Pseudo Operation Table
Ex:
• H DS F
the length of H is 4, since the size of 1 full word is 4 bytes.
• AC EQY 2
the length of AC is 1 byte, because if a symbol is equivalent to another,
its length is made the same as that of the other.
The relative location indicator tells the assembler whether the value of the symbol is absolute (A)
[i.e., the value of the symbol does not change if the program is moved in the core] or relative (R) to
the base of the program.
Ex:
• AC EQU 2 The relocation field of AC is A
• FOUR DC F ‘4’ The relocation field of FOUR is R
LT Literal Table
• It is a variable table that contains literals and its value.
• It is same like symbol table, instead of symbols, here we have literals.
Ex:
A 1, = F ‘4’
The literal table entries for this is as follows:
Base Register Number = the base register containing a value closest to the
symbolic reference.
Offset = value of symbol in symbol table – contents of base
register.
The following table summarizes the fixed and variable tables used by the 2 – pass
assembler
NAME OF
SL TYPE OF THE PASS 1 PASS 2
THE SIZE
NO TABLE ENTRIES ENTRIES
TABLE