Multiple choiceQuestion 1 · Recall
Loading…
By the end you can describe what a two-pass assembler does in each pass, build a symbol table for a small program, and explain why one pass would not be enough.
Read this program from the top, the way an assembler would:
100 LDM #3
101 STO 200
102 loop LDD 200
103 SUB 201
104 STO 200
105 CMP #0
106 JPN loop
107 END
Line 106 says JPN loop. The assembler has to put the address of loop into the machine code.
But loop is at address 102, and when the assembler reaches line 106 it has already passed it. In a one-pass assembler it would have needed that address before it knew it.
A label used before it is defined is called a forward reference. It is the entire reason assembling takes two passes.
Pass 1 reads the source code one line at a time and builds a map of the program. It does four jobs:
For the program above, pass 1 produces this symbol table:
| Label | Address |
|---|---|
loop |
102 |
Nothing is translated yet. Pass 1 is pure bookkeeping — but now loop has a known address even when the code jumps backwards or forwards to it.
Pass 2 reads the source code one line at a time again, and this time it produces output:
JPN loop → JPN 102);It is also the pass that can finally complain about a label that is never defined. Pass 1 cannot: it only knows a label is missing once it has read the whole program.