SP2.1 Assembler-Basic Assembler Functions
SP2.1 Assembler-Basic Assembler Functions
Tzong-Jye Liu
Department of Information Engineering and Computer Science
Feng Chia University
tjliu@fcu.edu.tw
Outline
System Programming 2
Basic assembler functions (1/2)
Source Program
• Mnemonic opcode Assembler Object code
• Symbol
System Programming 3
000000 1 1 0 0 1 0 00C
03200C
Question: FIVE 為⼀個 Symbol,如何計算 FIVE 的位址?
System Programming 4
Assembler directive
n Assembler directives (組譯器指引) are pseudo
instructions
n They provide instructions to the assembler itself
n They are not translated into machine operation codes
n SIC assembler directive
n START : specify name & starting address
n END : end of source program, specify the first
execution instruction
n BYTE, WORD, RESB, RESW
System Programming 5
System Programming 6
Example program (Figure 2.1 pp. 45) (2/4)
Forward
reference
System Programming 7
System Programming 8
Example program (Figure 2.1 pp. 45) (4/4)
System Programming 9
n Assembler’s functions
n Convert mnemonic operation codes to their machine
language equivalents
v Convert symbolic operands to their equivalent machine
addresses
n Decide the proper instruction format
n Convert the data constants to internal machine
representations
n Write the object program and the assembly listing
System Programming 10
Difficult
System Programming 11
System Programming 13
System Programming 14
Format of object program
(Figure 2.3 pp.49)
n Header record
Col. 1 H
Col. 2~7 Program name
Col. 8~13 Starting address of object program (hex)
Col. 14-19 Length of object program in bytes (hex)
n Text record
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)
n End record
Col.1 E
Col.2~7 Address of first executable instruction in object program (hex)
System Programming 16
The two passes of an assembler
n Pass 1 (define symbols)
n Assign addresses to all statements in the program
n Save the addresses assigned to all labels for use in Pass 2
n Perform assembler directives, including those for address
assignment, such as BYTE and RESW
n Pass 2 (assemble instructions and generate object
program)
n Assemble instructions (generate opcode and look up addresses)
n Generate data values defined by BYTE, WORD
n Perform processing of assembler directives not done during Pass 1
n Write the object program and the assembly listing
System Programming 17
Source Object
Pass 1 Intermediate Pass 2
Program Code
File
The intermediate file include each source statement, assigned address and error indicator
System Programming 18
OPTABLE
System Programming 19
LOCCTR
System Programming 20
SYMTAB
System Programming 21
Algorithm Pass 1
(Figure 2.4(a), pp.53)
System Programming 22
LABEL field
OPCODE
System Programming 23
1-token.c
2-optable.c
3-asm_pass1_u.c
SIC/XE Program Syntax
SYMBOL +INSTRUCTION [@|#]OPERAND1, OPERAND2 COMMENT ‘\n’
SYM + INST
S0 S1 S2 S3
INST
INST
(FMT1 || RSUB)
(FMT1 || RSUB) \n|EOF
SYM @|#
(comment) \n|EOF S8
(operand1)
SYM
(FMT2) \n|EOF
(operand2)
SYM SYM ,
(comment) S7 ’X’
S6 S5 SYM S4
(operand1)
SYM (comment)
System Programming 24
Algorithm Pass 2
(Figure 2.4(b), pp.54)
System Programming 25
OPERAND field
System Programming 26