Pass1 TwoPassAssembler
Pass1 TwoPassAssembler
1. Initialization
- Initialize Symbol Table (ST) to store labels and addresses.
- Initialize Location Counter (LC) using START directive or set to 0 if not provided.
2. Reading Instructions
- Read source code line by line.
- Parse each line into Label, Opcode, and Operands.
- Ignore comments.
4. Handling Labels
- If a label exists:
- Add it to the Symbol Table with the current LC.
- If already present, report a duplicate label error.
6. Modifying LC
- LC is updated after each instruction or data directive, depending on size.
7. Processing Literals
- Literals like ='5' are stored during parsing.
- At LTORG or END:
- Each is assigned an address.
- Literal Table is updated.
- LC is incremented accordingly.
8. Final Output of Pass 1
- Intermediate Code (IC) – Symbolic/tokenized version of each instruction.
- Symbol Table (ST) – All labels with assigned addresses.
- Literal Table (LT) – All literals with assigned addresses.
- Pool Table – Tracks literal groups if multiple LTORG directives exist.
Conclusion:
Pass 1 of a two-pass assembler is essential for resolving addresses and preparing
intermediate data. It constructs symbol and literal tables and generates intermediate code
required for Pass 2, where actual machine code is created.
LC Update Table
Instruction LC Before LC After
START 100 - 100
LOOP MOVER AREG, ='5' 100 101
ADD BREG, ONE 101 102
ONE DC 1 102 103
Literal ='5' 103 104
Symbol Table
Symbol Address
LOOP 100
ONE 102
Literal Table
Literal Address
='5' 103