0% found this document useful (0 votes)
28 views2 pages

Pass1 TwoPassAssembler

Pass 1 of a Two-Pass Assembler initializes the Symbol Table and Location Counter, reads source code to parse instructions, and processes labels while updating the Location Counter. It generates an Intermediate Code, Symbol Table, Literal Table, and Pool Table, preparing for Pass 2 where machine code is created. The process includes handling different instruction types, managing literals, and checking for duplicate labels.

Uploaded by

poojamaurya0812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Pass1 TwoPassAssembler

Pass 1 of a Two-Pass Assembler initializes the Symbol Table and Location Counter, reads source code to parse instructions, and processes labels while updating the Location Counter. It generates an Intermediate Code, Symbol Table, Literal Table, and Pool Table, preparing for Pass 2 where machine code is created. The process includes handling different instruction types, managing literals, and checking for duplicate labels.

Uploaded by

poojamaurya0812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Pass 1 of a Two-Pass Assembler

Pass 1 of a Two-Pass Assembler – Full Marks Answer

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.

3. End of File Check


- On encountering END or end of file:
- Process any pending literals (assign addresses).
- Transition to Pass 2.

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.

5. Processing Different Instruction Types


a. IS – Instruction Statements
- Example: ADD, MOVER, SUB.
- Update LC (usually increment by 1).
b. ORIGIN
- Used to change LC using an expression.
c. DL – Declarative Statements
- Includes DC, DS.
- Reserves memory; updates LC based on size.
d. LTORG
- Assigns addresses to collected literals.
- If missing, literals processed at END.

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.

Example Assembly Program:


START 100
LOOP MOVER AREG, ='5'
ADD BREG, ONE
ONE DC 1
END

Data Structures Used:


- Symbol Table: Stores labels and addresses.
- Literal Table: Stores literals and addresses.
- Pool Table: Tracks literal groups.
- Intermediate Code: Used in Pass 2 for final machine code generation.

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

You might also like