SP2.4 Assembler-Design-Options
SP2.4 Assembler-Design-Options
Tzong-Jye Liu
Department of Information Engineering and Computer Science
Feng Chia University
[email protected]
Outline
n One-pass assemblers
n Multi-pass assemblers
n Two-pass assembler with overlay structure
System Programming 3
One-Pass Assemblers
n Scenario for one-pass assemblers
n Generate their object code in memory for immediate execution –
load-and-go assembler
n External storage for the intermediate file between two passes is slow
or is inconvenient to use
n Main problem
n Forward references
n Data items
n Labels on instructions
n Solution
n Require that all areas be defined before they are referenced.
n It is possible, although inconvenient, to do so for data items.
n Forward jump to instruction items cannot be easily eliminated.
n Insert (Label, address to be modified) to SYMTAB
n Usually, address to be modified is a linked-list
System Programming 4
Sample program for a one-pass assembler
Figure 2.18, pp. 94
Forward Reference
in One-pass Assembler
n Omits the operand address if the symbol has not yet been
defined
n Enters this undefined symbol into SYMTAB and indicates that it
is undefined
n Adds the address of this operand address to a list of forward
references associated with the SYMTAB entry
n When the definition for the symbol is encountered, scans the
reference list and inserts the address.
n At the end of the program, reports the error if there are still
SYMTAB entries indicated undefined symbols.
n For Load-and-Go assembler
n Search SYMTAB for the symbol named in the END statement and jumps
to this location to begin execution if there is no error
System Programming 6
Object Code in Memory and SYMTAB
Figure 2.19(a), pp.95
After scanning line 40 of prog. In Fig. 2.18
System Programming 7
System Programming 9
System Programming 10
Multi-Pass Assemblers
System Programming 11
Implementation
n For a forward reference in symbol definition, we store
in the SYMTAB:
n The symbol name
n The defining expression
n The number of undefined symbols in the defining expression
n The undefined symbol (marked with a flag *)
associated with a list of symbols depend on this
undefined symbol.
n When a symbol is defined, we can recursively
evaluate the symbol expressions depending on the
newly defined symbol.
System Programming 12
Multi-pass assembler example
Figure 2.21, pp. 99-101
# of undefined symbols in the
defining expression
The defining expression
Depending list
Undefined symbol
System Programming 13
System Programming 14
Multi-pass assembler example
Figure 2.21, pp. 99-101
System Programming 15
Two-pass assembler
with overlay structure
n When memory is not enough
n Pass 1 and pass 2 are never required at the same time
n Three segments
n Overlay program
System Programming 16