Module 2
Module 2
l Source Object
l
lCode
lProgram Assembler Linker
Executable
l
lCode
Loader
What is assembly language?
EX A DS 1F
ONE DC F'1'
Assembler Directives
-Not translated into machine instructions
-Providing information to the assembler
l Ex START 100
USING *, 15
Advance Assembler Directives
ORIGIN-
This directive instructs the assembler to put the address given by <address
specification> in the location counter
EQU-
The statement simply associates the name <symbol> with the address
specified by <address specification>. However, the address in the location
counter is not affected.
LTORG-
The LT0RG directive, which stands for 'origin for literals', allows a
programmer to specify where literals should be placed.
14 NUM DS 1 513
15 ANSWER DS 1 514
17 TEMP DS 1 516
18 END
Assembler Directives
START <constant>
END <operand spec>
ORIGIN <address
specification> EQU <symbol>
EQU <addr> LTORG
USING <symbol>,<base
Register> PUBLIC & EXTRN
SEGMENT,ENDS,ASSUME
PURGE
Pre-defined Tables
Machine Instruction Format
Intermediate Representation
Variant lI
This variant differs from variant I of the intermediate
code because in variant II symbols, condition codes and
CPU register are not processed.
General Design Procedure of
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
•The assembler must do following.
1) Generate Instructions
a) Evaluate the mnemonic in the operation field.
b) Evaluate Sub fields.
2) Process Pseudo ops.
Types of Assembler
4) Specify Algorithms
Pass1: Databases
•Input source program
• “LC” location counter used to keep track of each
instructions address.
•M/c operation table (MOT) [Symbolic mnemonic & length]
•Pseudo operation table [POT], [Symbolic mnemonic &
action]
•Symbol Table (ST) to store each lablel & it’s value.
•Literal Table (LT), to store each literal (variable) & it’s
location.
•Copy of input to used later by PASS-2.
Pass2: Generate object program
1) Look up value of symbols [ST]
2) Generate instruction [MOT]
3) Generate data (for DS, DC & literals)
4) Process pseudo ops[POT]
Step 2- Specify Data structure
•Pass2: Databases
•Copy of source program input to Pass1.
•Location Counter (LC)
•MOT [Mnemonic, length, binary m/c op code,Format]
•POT [Mnemonic & action to be taken in Pass2
•ST [prepared by Pass1, label & value]
• Base Table [or register table] indicates which registers
are currently specified using ‘USING’ pseudo op & what
are
contents.
•Literal table prepared by Pass1. [Lit name & value].
Step 3 -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
Pass-II
Assembler
Flow-Chart
Assembler Pass-I (Algorithm)
1.loc_cntr = 0 ; (default value)
pooltab_ptr =
1;
poolTAB [1] =
littab_ptr = 1;
1;
1. While next statement is not an END statement
(a) if label is present then
this_label = symbol in label field;
Enter (this_label , loc_cntr) in SYMTAB
(b) If an LTORG statement then
Process literals LITTAB [POOLTAB] to allocate memory
and put the address in address field. Update loc_cntr
accordingly.
pooltab_ptr = pooltab_ptr + 1;
POOLTAB [pooltab_ptr] = littab_ptr ;