Introduction of Assembler
Introduction of Assembler
Assembly Program:
Label Op-code operand LC value(Location counter)
JOHN START 200
MOVER R1, ='3' 200
MOVEM R1, X 201
L1 MOVER R2, ='2' 202
LTORG 203
X DS 1 204
END 205
Let’s take a look on how this program is working:
1. START: This instruction starts the execution of program from
location 200 and label with START provides name for the program.
(JOHN is name for program)
2. MOVER: It moves the content of literal(=’3′) into register operand
R1.
3. MOVEM: It moves the content of register into memory operand(X).
4. MOVER: It again moves the content of literal(=’2′) into register
operand R2 and its label is specified as L1.
5. LTORG: It assigns address to literals(current LC value).
6. DS(Data Space): It assigns a data space of 1 to Symbol X.
7. END: It finishes the program execution.
Working of Pass-1: Define Symbol and literal table with their addresses.
Note: Literal address is specified by LTORG or END.
Step-1: START 200 (here no symbol or literal is found so both table would
be empty)
Step-2: MOVER R1, =’3′ 200 ( =’3′ is a literal so literal table is made)
Literal Address
=’3′ –––
X –––
X –––
L1 202
Literal Address
=’3′ –––
Literal Address
=’2′ –––
=’3′ 203
=’2′ –––
Step-6: X DS 1 204
It is a data declaration statement i.e X is assigned data space of 1. But X is a
symbol which was referred earlier in step 3 and defined in step 6.This
condition is called Forward Reference Problem where variable is referred
prior to its declaration and can be solved by back-patching. So now
assembler will assign X the address specified by LC value of current step.
Symbol Address
X 204
L1 202
X 204
L1 202
Literal Address
=’3′ 203
=’2′ 205
Now tables generated by pass 1 along with their LC value will go to pass-2 of
assembler for further processing of pseudo-opcodes and machine op-codes.
Working of Pass-2:
Pass-2 of assembler generates machine code by converting symbolic
machine-opcodes into their respective bit configuration(machine
understandable form). It stores all machine-opcodes in MOT table (op-code
table) with symbolic code, their length and their bit configuration. It will also
process pseudo-ops and will store them in POT table(pseudo-op table).
Various Data bases required by pass-2:
1. MOT table(machine opcode table)
2. POT table(pseudo opcode table)
3. Base table(storing value of base register)
4. LC ( location counter)
Take a look at flowchart to understand:
As a whole assembler works as: