OnePass Assembler MultiPass Assembler One and MultiPass Assembler

One-Pass Assembler & Multi-Pass Assembler

One and Multi-Pass Assembler n n So far, we have presented the design and implementation of a two-pass assembler. Here, we will present the design and implementation of n One-pass assembler n n Multi-pass assembler n 2 If avoiding a second pass over the source program is necessary or desirable. Allow forward references during symbol definition. Tuesday, June 15, 2021

One-Pass Assembler n n The main problem is about forward reference. Eliminating forward reference to data items can be easily done. n n However, eliminating forward reference to instruction cannot be easily done. n n 3 Simply ask the programmer to define variables before using them. Sometimes your program needs a forward jump. Asking your program to use only backward jumps is too restrictive. Tuesday, June 15, 2021

One-Pass Assemblers n Main problem n Forward references Data items n Labels on instructions n n Solution n n 4 Data items: require all such areas be defined before they are referenced Labels on instructions: no good solution Tuesday, June 15, 2021

One-Pass Assemblers n Two types of one-pass assembler n Load-and-go n n The other n 5 Produces object code directly in memory for immediate execution Produces usual kind of object code for later execution Tuesday, June 15, 2021

Two types of one-pass assembler n There are two types of one-pass assembler: n Produce object code directly in memory for immediate execution No loader is needed n Load-and-go for program development and testing n Good for computing center where most students reassemble their programs each time. n Can save time for scanning the source code again n n 6 Produce the usual kind of object program for later execution Tuesday, June 15, 2021

Load-and-go Assembler n Characteristics n n 7 Avoids the overhead of writing the object program out and reading it back Both one-pass and two-pass assemblers can be designed as load-and-go. However one-pass also avoids the over head of an additional pass over the source program For a load-and-go assembler, the actual address must be known at assembly time, we can use an absolute program Tuesday, June 15, 2021

Load-and-go Assembler n Forward references handling 1. Omit the address translation 2. Insert the symbol into SYMTAB, and mark this symbol undefined 3. The address that refers to the undefined symbol is added to a list of forward references associated with the symbol table entry 4. When the definition for a symbol is encountered, the proper address for the symbol is then inserted into any instructions previous generated according to the forward reference list 8 Tuesday, June 15, 2021

Load-and-go Assembler n At the end of the program n n n 9 Any SYMTAB entries that are still marked with * indicate undefined symbols Search SYMTAB for the symbol named in the END statement and jump to this location to begin execution The actual starting address must be specified at assembly time Tuesday, June 15, 2021

10 Tuesday, June 15, 2021

11 Tuesday, June 15, 2021

All variables are defined before they are used. 12 Tuesday, June 15, 2021

Processing Example After scanning line 40 13 Tuesday, June 15, 2021

Processing Example 14 After scanning line 160 Tuesday, June 15, 2021

Processing Example n Between scanning line 40 and 160: n n On line 45, when the symbol ENDFIL is defined, the assembler places its value in the SYMTAB entry. The assembler then inserts this value into the instruction operand field (at address 201 C). From this point on, any references to ENDFIL would not be forward references and would not be entered into a list. At the end of the processing of the program, any SYMTAB entries that are still marked with * indicate undefined symbols. n 15 These should be flagged by the assembler as errors. Tuesday, June 15, 2021

One Pass Assembler Algorithm 16 Tuesday, June 15, 2021

One Pass Assembler Algorithm 17 Tuesday, June 15, 2021

Figure 2. 20 18 Tuesday, June 15, 2021

Multi-Pass Assemblers n Restriction on EQU and ORG n n Example n 19 No forward reference, since symbols’ value can’t be defined during the first pass Use link list to keep track of whose value depend on an undefined symbol Tuesday, June 15, 2021

Multi-Pass Assembler n If we use a two-pass assembler, the following symbol definition cannot be allowed. ALPHA BETA DELTA n n 20 EQU RESW BETA DELTA 1 This is because ALPHA and BETA cannot be defined in pass 1. Actually, if we allow multi-pass processing, DELTA is defined in pass 1, BETA is defined in pass 2, and ALPHA is defined in pass 3, and the above definitions can be allowed. This is the motivation for using a multi-pass assembler. Tuesday, June 15, 2021

Multi-Pass Assembler n n n 21 It is unnecessary for a multi-pass assembler to make more than two passes over the entire program. Instead, only the parts of the program involving forward references need to be processed in multiple passes. The method presented here can be used to process any kind of forward references. Tuesday, June 15, 2021

Multi-Pass Assembler Implementation n n Use a symbol table to store symbols that are not totally defined yet. For a undefined symbol, in its entry, n n 22 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. Tuesday, June 15, 2021

23 Tuesday, June 15, 2021

24 Tuesday, June 15, 2021

25 Tuesday, June 15, 2021

26 Tuesday, June 15, 2021

27 Tuesday, June 15, 2021
- Slides: 27