Assembler Design Options: One-Pass Assemblers Multi-Pass Assemblers

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Assembler Design Options

One-pass assemblers
Multi-pass assemblers
One-Pass Assemblers
● Object code is generated in a single pass.
● Main problem
● forward references (Instruction operands
often are symbols that have not yet been
defined in the source program. Thus the
assembler does not know what address to
insert in the translated instruction)
● Solution
● data items: require all such areas be
defined before they are referenced Chap 2
One-Pass Assemblers

● Two types of one-pass assembler


● load-and-go
● produces object code directly in memory for
immediate execution
● the other
● produces usual kind of object code for later
execution

Chap 2
Eg: Forward reference free program
MOVE START 1000
ALPHARESW 1
FIVE WORD 5
CHARZ BYTE C’Z’
C1 RESB 1
LDA FIVE
STA ALPHA
LDCH CHARZ
STCH C1
END
Chap 2
SYMTAB for the above program
LABEL ADDRESS
ALPHA 1000
FIVE 1003
CHARZ 1006
C1 1007

Chap 2
Object code
MOVE START 1000
ALPHARESW 1
FIVE WORD 5 000005
CHARZ BYTE C’Z’ 5A
C1 RESB 1
LDA FIVE 001003
STA ALPHA0C1000
LDCH CHARZ 501006
STCH C1 541007
END
Chap 2
DEALING WITH FORWARD
REFERENCE
MOVE START 1000
ALPHA RESW 1
LDA FIVE
STA ALPHA
FIVE WORD 5
END

Chap 2
When encounter FIVE as operand(which is not in
SYMTAB), insert FIVE and a * with a reference to
1004.
LABEL ADDRESS
ALPHA 1000
FIVE * 1004

When encounter FIVE as label, replace * with 1009


and fill that address in 1004.

LABEL ADDRESS
ALPHA 1000
FIVE 1009
Chap 2
Object code
MOVE START 1000
ALPHA RESW 1
LDA FIVE 00----
STA ALPHA 0C1000
FIVE WORD 5 000005
END
001009

Chap 2
Load-and-go Assembler
● Characteristics
● Useful for program development and testing
● 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
Chap 2
Forward Reference in One-pass Assembler

● For any symbol that has not yet been defined


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

Chap 2
Load-and-go Assembler (Cont.)
● At the end of the program
● 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
● Example
● Figure 2.18Figure 2.18, 2.19

Chap 2
Chap 2
Chap 2

You might also like