Sei sulla pagina 1di 5

Assemblers (continued) • Assembler assumes the starting address to be

zero.
Program Relocation: • Assembler identifies parts of the object pro-
gram that need to be modified when the pro-
Example 1: Suppose the START directive in a gram is relocated.
program for SIC specifies 100, the instruction
Modification Record:
LDA THREE
has LC value = 103, and the symbol THREE • Each time the assembler produces an instruc-
has LC value = 115. The assembled form of the tion with an address, a modification record is
instruction (in hex) is 000073. produced.
• Each modification record contains
• The above instruction uses absolute addresses.
(a) Starting location of the address field to
• Works correctly as long as the program starts be modified.
from location 100.
(b) Length of the address field (in say, bytes,
• Requirement too rigid in a multiprogramming half-bytes or bits).
environment.
• Modification records are appended to the ob-
• Relocatable program: A program that ject code.
works correctly regardless of starting address.
Example 2: Relocatable translation for the in-
• Assembler should produce relocatable object
struction in Example 1.
code.
3–1 3–2
• The object code produced is 00000F. Literals:
• Modification record: Starting location = 4 • Literal: Constant operand written as part of
and Length = 15 (bits). the instruction.
Relocation for SIC and SIC/XE: Example:

• SIC: All instructions except RSUB and I/O in- LDA =C’PQR’
structions cause a modifier record to be writ- TD =X’05’
ten.
• Literals are different from immediate operands.
• SIC/XE: Only 4-byte instructions may cause
a modifier record to be written. Example: The SIC/XE statement
LDA #112
Errors Detected by Assemblers:
will be assembled into the 3-byte instruction 010070
• Undefined symbols. (These are usually indi- (hex). However, the statement
cated at the end of the program listing.) LDA =C’PQR’
• Multiply defined symbols. is equivalent to
• Illegal opcode. LDA LIT1
.
• Missing or extra operands. .
• Relative addressing infeasible (SIC/XE). LIT1 BYTE =C’PQR’

3–3 3–4
• Assembler may create new (special) labels for Symbol Defining Directives:
literals.
• EQU directive is useful in defining constants.
• Normally, a “literal pool” is created at the end
of a program. Example:
• Assembler may choose to have the literal pool MAXADR EQU 65535
at a different point (instead of at the end) to
allow PC-relative addressing. • Allows instructions such as
• A special directive LTORG used for this LDA #MAXADR
purpose.
• Symbol Table can be used to handle such
Example: constants.
LDA =C’PQR’
. Handling Expressions:
.
J NEXT • Expressions may involve constants.
LTORG
. Example:
. NREC EQU 200
NEXT LDB #80 RSIZE EQU 15
.
• Some assemblers use a Literal Table to save
.
space for duplicate literals.
LOC RESW NREC*SIZE
3–5 3–6
• Expressions may also involve addresses. (a) Load-and-Go Assemblers:
Example: • Intermediate version and final object code are
STA START+2 kept in main memory.
• Program can begin execution right after as-
• Expression evaluation needed in both passes. sembly.
– Values of expressions used with RESW and
• To handle forward references, modify Symbol
RESB directives must be computed in
Table (ST).
Pass 1.
– Values of expressions such as START+2 may • Each ST entry for a two-pass assembler has
need to be computed in Pass 2. symbol and LC value.

• Expression evaluation algorithm: • Each ST entry for a one-pass assembler has:


1. Convert expression to postfix form. – Symbol
2. Evaluate postfix expression using a stack. – Defined? (Boolean flag)
– LC Value
One-Pass Assemblers:
– Pointer to the list of locations where the LC
• One-pass: Assembler makes only one physical value for the symbol is needed.
pass over the source file.
Outline of Algorithm: See Handout 3.1.
• Main problem: Forward references.
Example: To be discussed in class using the
• Two types: Load-and-go and Object file as- program segment in Handout 3.2.
semblers.
3–7 3–8
(b) Object File Assemblers: Multi-pass Assemblers:

• Object code bytes written out to the file are • Two passes may not be enough.
“unavailable” for patching.
Example:
• Patching is done at run time (by the loader).
ALPHA EQU BETA
• As in load-and-go assemblers, use the modi-
DELTA EQU ALPHA
fied symbol table and store forward references
.
as linked lists.
.
• When a symbol gets defined, output a text ARRAY RESW ALPHA
record for each forward reference of the sym- .
bol using the list. .
DELTA EQU 24
Example: To be discussed in class using the
program segment in Handout 3.2.
• Multi-pass assemblers are not common.
– Assembly takes more time.
– Handling ST requires additional overhead.
(A symbol may appear in the label field
many times.)
– Such programs are more difficult to under-
stand.
3–9 3–10

Potrebbero piacerti anche