Академический Документы
Профессиональный Документы
Культура Документы
Multi-pass assembler
One-pass assemblers
A one-pass assembler scans the program just once. The main problem in trying to assemble a program in one pass involves forward references.
The one-pass assembler must make some special provision for handling forward references.
Load-and-go assembler
The assembler that does not write object program out and does not need a loader is called a load-and-go assembler.
Source Program
Load-and-go assembler
Assembler
the symbol is entered into the symbol table with a flag indicating that the symbol is undefined; the operand address is omitted when the instruction is assembled; the operand address is added to a list of forward references associated with the symbol table entry.
When the definition for a symbol is encountered, the forward reference list for that symbol is scanned, and the proper address is inserted into any instructions previously generated.
Object code in memory and symbol table entries after scanning line 40
Object code in memory and symbol table entries after scanning line 160
10
the assembly is complete; the assembler searches SYMTAB for the value of the symbol named in the END statement and jumps to this location to begin execution of the assembled program.
END
11
One-pass assembler
One-pass assemblers that product object programs as output are often used on
12
Object code without addresses of undefined operands can be written out as part of a Text record in the object program.
When the definition of a forward reference is encountered, the assembler generates Text records with the correct operand address. In effect, the services of the loader are being used to complete forward references that could not be handled by the assembler.
13
14
15
16
17
Multi-pass assemblers
In previous discussions, forward references in symbol definition are not allowed. the any symbol used on the right-hand side of the EQU (or ORG) assembler
directives must be defined.
ALPHA BETA DELTA EQU EQU RESW BETA DELTA 1
To eliminate the need of such restriction, the general solution is a multi-pass assembler that can make as many passes as are needed to process the definitions of symbols.
However, only the parts of the program involving forward references need to be processed in multiple passes. It is unnecessary for such an assembler to make more than two passes over the entire program. The method presented here can be used to process any kind of forward references
18
We store the names and the number of undefined symbols which contribute to the calculation of its value. We also keep a list of symbols whose values depend on the defined value of this symbol.
When a symbol becomes defined, we use its value to reevaluate the values of all of the symbols that are kept in this list. The above step is performed recursively.
19
1 2 3 ... 4 5
20
10
21
22
11
23
24
12