Вы находитесь на странице: 1из 12

Assembler Design Options

One and Multi-pass Assembler


One-pass assembler

The one-pass assembler is used if it is


necessary and desirable to avoid a second pass over the source program.

Multi-pass assembler

The multi-pass assembler allows forward


references during symbol definition.

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.

Can we write a program without forward references?


All storage reservation statements can be defined before they are referenced. But, forward references to labels on instructions cannot be eliminated as easily.

The logic of the program often needs a forward jump.

The one-pass assembler must make some special provision for handling forward references.

Two types of one-pass assemblers


One type of one-pass assemblers produces object code directly in memory for immediate execution.

No object program is written out. No loader is needed.


The other type of one-pass assemblers produces the usual kind of object program for later execution.

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.

It avoids the overhead of writing the object


program out and reading it back in. It is useful in a system that is oriented toward program development and testing. A load-and-go assembler can be a onepass assembler or a two-pass assembler.
6

Load-and-go assembler (contd)


Program loaded in memory

Source Program

Load-and-go assembler

Assembler

Handling of forward references in one-pass load-and-go assembler


The assembler generates object code instructions as it scans the source program. If an instruction operand is a symbol that has not yet been defined,

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

refer to undefined symbols


9

Object code in memory and symbol table entries after scanning line 160

10

One-pass load-and-go assembler


For a load-and-go assembler, the actual address must be known at assembly time. When the end of the program is encountered,

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.

jump to this location


FIRST

END

11

One-pass assembler
One-pass assemblers that product object programs as output are often used on

systems where external working-storage


device for the intermediate file between the two passes are not available. systems with slow external storages.

12

One-pass assembler (contd)


Forward references are entered into lists as before.

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

Object program from one-pass assembler

14

Sample program for one-pass assembler (1/3)


absolute program

15

Sample program for one-pass assembler (2/3)

16

Sample program for one-pass assembler (3/3)

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

Multi-pass Assembler Implementation


Use a symbol table to store symbols that are not totally defined yet. For a undefined symbol, in its entry,

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

Multi-pass operation (1/5)


remain one undefined symbol enter SYMTAB

1 2 3 ... 4 5

HALFSZ MAXLEN PREVBT BUFFER BUFEND

EQU EQU EQU REB EQU

MAXLEN/2 BUFEND-BUFFER BUFFER-1 4096 *

enter SYMTAB as undefined

The lists contains symbols referring MAXLEN

20

10

Multi-pass operation (2/5)


1 2 3 ... 4 5 HALFSZ MAXLEN PREVBT BUFFER BUFEND EQU EQU EQU REB EQU MAXLEN/2 BUFEND-BUFFER BUFFER-1 4096 *

21

Multi-pass operation (3/5)


1 2 3 ... 4 5 HALFSZ MAXLEN PREVBT BUFFER BUFEND EQU EQU EQU REB EQU MAXLEN/2 BUFEND-BUFFER BUFFER-1 4096 *

22

11

Multi-pass operation (4/5)


1 2 3 ... 4 5 HALFSZ MAXLEN PREVBT BUFFER BUFEND EQU EQU EQU REB EQU MAXLEN/2 BUFEND-BUFFER BUFFER-1 4096 *

23

Multi-pass operation (5/5)


1 2 3 ... 4 5 HALFSZ MAXLEN PREVBT BUFFER BUFEND EQU EQU EQU REB EQU MAXLEN/2 BUFEND-BUFFER BUFFER-1 4096 *

24

12

Вам также может понравиться