Col. 1
T
Col. 2~7
Starting address for object code in this record (hex)
Col. 8~9
Length of object code in this record in bytes (hex)
Col. 10~69 Object code, represented in hex (2 col. per byte)
∎
End record
Col.1
E
Col.2~7
Address of first executable instruction in object program (hex)
∎ "^" is only for separation only
Page 15
15
Format of object program
(Figure 2.3 pp.49)
Address 1033 ~ 2038: reserve storage by loader
• RETADR: 3 bytes
• LENGTH: 3 bytes
• BUFFER: 4096 bytes = (1000)16
Page 16
16
The two passes of an assembler
∎ Pass 1 (define symbols)
∎
Assign addresses to all statements in the program
∎
Save the addresses assigned to all labels for use in Pass 2
∎
Perform assembler directives, including those for address
assignment, such as BYTE and RESW
∎ Pass 2 (assemble instructions and generate object
program)
∎
Assemble instructions (generate opcode and look up addresses)
∎
Generate data values defined by BYTE, WORD
∎
Perform processing of assembler directives not done during Pass 1
∎
Write the object program and the assembly listing
Page 17
17
Assembler algorithm
and data structures
∎ OPTAB: operation code table
∎ SYMTAB: symbol table
∎ LOCCTR: location counter
Source
Program
Object
Code
Pass 1
Intermediate
File
Pass 2
OPTAB
SYMTAB
LOCCTR
Assembler
The intermediate file include each source statement, assigned address and error indicator
Page 18
18
OPTABLE
∎ Mnemonic operation codes ⇔ Machine code
∎ Contain instruction format and length
∎ LOCCTR ← LOCCTR + (instruction length)
∎ Implementation
∎ It is a static table
∎ Array or hash table
∎ Usually use a hash table (mnemonic opcode
as key)
Page 19
19
LOCCTR
∎ Initialize to be the beginning address
specified in the "START" statement
∎ LOCCTR ← LOCCTR + (instruction length)
∎ The current value of LOCCTR gives the
address to the label encountered
Page 20
20
SYMTAB
∎ Label name ⇔ label address, type, length, flag
∎ To indicate error conditions (Ex: multiple define)
∎ It is a dynamic table
∎ Insert, delete and search
∎ Usually use a hash table
∎ The hash function should perform non-random
key (Ex: LOOP1, LOOP2, X, Y, Z)
Page 21
21
Algorithm Pass 1
(Figure 2.4(a), pp.53)
Page 22
22
Algorithm Pass 2
(Figure 2.4(b), pp.54)
assembler
Start from the beginning
