12
1 Assembler Design Options 2 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.

1 Pass & Multi Pass

Embed Size (px)

Citation preview

Page 1: 1 Pass & Multi Pass

1

Assembler Design Options

2

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.

Page 2: 1 Pass & Multi Pass

2

3

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.

4

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.

Page 3: 1 Pass & Multi Pass

3

5

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.

6

Load-and-go assembler

The assembler that does not write object program out and does not need a loader is called a load-and-goassembler.• 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 one-

pass assembler or a two-pass assembler.

Page 4: 1 Pass & Multi Pass

4

7

Load-and-go assembler (cont’d)

SourceProgram

Load-and-goassembler

Assembler

Programloaded

in memory

8

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.

Page 5: 1 Pass & Multi Pass

5

9

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

c refer to undefined symbols

10

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

Page 6: 1 Pass & Multi Pass

6

11

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.

END FIRST

jump to this location

12

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.

Page 7: 1 Pass & Multi Pass

7

13

One-pass assembler (cont’d)

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.

14

Object program from one-pass assembler

Page 8: 1 Pass & Multi Pass

8

15

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

absolute program

16

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

Page 9: 1 Pass & Multi Pass

9

17

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

18

Multi-pass assemblersIn 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 EQU BETABETA EQU DELTADELTA RESW 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

Page 10: 1 Pass & Multi Pass

10

19

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.

20

Multi-pass operation (1/5)1 HALFSZ EQU MAXLEN/22 MAXLEN EQU BUFEND-BUFFER3 PREVBT EQU BUFFER-1...4 BUFFER REB 40965 BUFEND EQU *

remain one undefined symbol

enter SYMTAB

enter SYMTAB as undefined The lists contains symbols referring MAXLEN

Page 11: 1 Pass & Multi Pass

11

21

Multi-pass operation (2/5)

1 HALFSZ EQU MAXLEN/22 MAXLEN EQU BUFEND-BUFFER3 PREVBT EQU BUFFER-1...4 BUFFER REB 40965 BUFEND EQU *

22

Multi-pass operation (3/5)

1 HALFSZ EQU MAXLEN/22 MAXLEN EQU BUFEND-BUFFER3 PREVBT EQU BUFFER-1...4 BUFFER REB 40965 BUFEND EQU *

Page 12: 1 Pass & Multi Pass

12

23

Multi-pass operation (4/5)

1 HALFSZ EQU MAXLEN/22 MAXLEN EQU BUFEND-BUFFER3 PREVBT EQU BUFFER-1...4 BUFFER REB 40965 BUFEND EQU *

24

Multi-pass operation (5/5)1 HALFSZ EQU MAXLEN/22 MAXLEN EQU BUFEND-BUFFER3 PREVBT EQU BUFFER-1...4 BUFFER REB 40965 BUFEND EQU *