Académique Documents
Professionnel Documents
Culture Documents
Pass 1:
Step 1:
1) Prepare and initialize all data structures like MOT, POT, ST etc.
2) Open input soured file and output intermediate file in respective mode.
3) Initialize all pointers(i.e. MOTPTR, POTPTR etc.) to point to the first
entry.
4) Initialize the LC to .
5) Set error flag = OFF
Step 2:
Case 4:
Statement contains mnemonic and operand. (e.g. LOAD A)
Search MOT for mnemonic
Search operand in ST if present do nothing.
else insert operand in ST
LC = LC + length of instruction
GOTO STEP 2
Case 5:
Statement contains label and mnemonic (e.g. back : STOP)
Check whether label is present in ST
if not present
insert label in ST & attribute as L
address of label is set to LC
insert this address against label in ST
else error duplicate label . And set error flag = ON
Search MOT for mnemonic
LC = LC + length of instruction
GOTO STEP 2
Case 6 :
Statement contains label, mnemonic and operand (e.g.
LOOP: jmp loop)
Check whether label is present in ST
if not present
insert label in ST & attribute as L
address of label is set to LC
insert this address against label in ST
else error duplicate label . And set error flag = ON
Search MOT for mnemonic
Search operand in ST
If present
do nothing
else
insert operand in ST
LC = LC + length of instruction
GOTO STEP 2
Case 7:
Statement contains pseudo opcode
Case 7.1: Statement contains pseudo opcode START or ORG (e.g.
ORG 1)
Search POT for pseudo opcode
Read the next operand and initialize LC with the value of the operand
GOTO STEP 2
- GOTO STEP 2
Case 9.2 : Procedure definition ends
- reset the respective procedure definition flag
to
- write total length taken by procedure, (if
reqd) in ST
- GOTO STEP 2
Case 9.3 : Procedure call
Case 10 : Default
An assembler comes to this state only if the instruction is invalid i.e it is
not starting with label, mnemonic or pseudo opcode or comment
- ignore the line
Pass 2 of an assembler:
Step 1:
1) Assuming all tables are initialized in pass 1, initialize table pointers.
2) Open input source file and output target file in respective mode.
3) Initialize all pointers (i.e. MOTPTR, POTPTR etc.) to point to the first
entry.
4) Initialize the LC to .
Step 2:
Read a line of source code
If end of file or END pseudo opcode
Assembly complete. Reset all tables, variables and close all files.
else goto step 3.
Step 3:
Analyze the statement
Case 1: Statement contains only comment.
Start form SOC i.e. start of comment and ignore everything till EOC
i.e. end of comment
GOTO STEP 2
Case 2:
Case 3:
Case 4:
Case 5:
Case 6:
loop)
LC = LC + length of instruction
GOTO STEP 2
Case 7:
Statement contains pseudo opcode
Case 7.1: Statement contains pseudo opcode START or ORG (e.g. ORG 1)
Search POT for pseudo opcode
Read the next operand and initialize LC with the value of the operand
GOTO STEP 2
2) LC = LC +1
3) write this constant value in output file
GOTO STEP 2
Case 7.6 : Statement contains pseudo code END
Search POT for pseudo code
End of assembly