Lecture 03
Lecture 03
SYSTEM
PROGRAMMING
Dr. Abeer Alsheaibi
1
Outlines
◦ Assembler
◦ Definition
◦ Directives
◦ Data structure
2
3
Definition of Assembler
◦ An assembler is a kind of translator that
accepts the input in assembly language
program and produces its machine language
equivalent.
◦ Ex: MASM, TASM
Basic Assembler Functions
1. Convert mnemonic operation codes to their
machine language equivalents
◦ Ex: LDA -> 00, JSUB ->48
2. Convert symbolic operands to their equivalent
machine addresses
◦ Ex: STA TABLE
3. Build machine instructions in proper format
(format 1, 2, 3, or 4)
4
Basic Assembler Functions
4. Convert data constants into internal machine
representations.
◦ Ex: EOF -> 4546
5. Write object program and the assembly listing
5
Assembler Directives
◦ Basic assembler directives (pseudo
instructions):
◦ They provide definition to the assembler itself.
◦ They are not translated into machine operation
code.
◦ START :
◦ Specify name and starting address for the program
◦ Ex: SUM START 4000
◦ END :
◦ Indicate the end of the source program, and (optionally)
the first executable instruction in the program.
◦ Ex: END 4000
6
Assembler Directives
◦ BYTE :
◦ Generate character or hexadecimal constant,
occupying as many bytes as needed to represent the
constant.
◦ WORD :
◦ Generate one-word integer constant (1 word ≡ 3
bytes)
◦ RESB :
◦ Reserve the indicated number of bytes for a data area
◦ Ex: RESB 10
◦ RESW :
◦ Reserve the indicated number of words for a data
area
◦ Ex: RESW 10 7
SIC Assembly Program
Line numbers Mnemonic opcode
(for reference)
comments
Fixed format
Address labels operands
8
SIC Assembly Program
Indicate comment lines
Index addressing 9
SIC Assembly Program
10
Forward Reference
◦ Definition
◦ A reference to a label that is defined later in
the program
◦ Solution
◦ Two passes
◦ First pass: scan the source program for label definition,
address accumulation, and address assignment
◦ Second pass: perform most of the actual instruction
translation
11
Object Program Format
◦ Header
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)
◦ Text
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
Col.1 E
Col.2~7 Address of first executable instruction in object program (hex)
14
Data Structures - LOCCTR
◦ A variable accumulated for address assignment,
i.e., LOCCTR gives the address of the associated
label.
◦ LOCCTR is initialized to be the beginning address
specified in the START statement.
◦ After each source statement is processed during
pass 1, instruction length or data area is added
to LOCCTR.
15
Data Structures - OPTAB
16
Data Structures - SYMTAB
◦ Contents:
◦ Label name
◦ Label address
◦ Flags (to indicate error conditions)
◦ Data type or length
◦ During pass 1:
◦ Store label name and assigned address (from
LOCCTR) in SYMTAB
◦ During pass 2:
◦ Symbols used as operands are looked up in
SYMTAB
17
SIC Machine – Generate Object Program
18
SIC Machine – Generate Object Program
19
SIC Machine – Generate Object Program
20
SIC Machine – Generate Object Program
21
SIC Machine – Generate Object Program
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)
22
SIC Machine – Generate Object Program
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)
23
SIC Machine – Generate Object Program
End record:
◦ Col.1 E
◦ Col.2-7 Address of first executable instruction in object
program (hex)
24
SIC Machine – Generate Object Program
25
Assembler Data Structures
26
SIC Machine – Generate Object Program
Pass 1 Pass 2
27
Two Pass Assembler – Pass 1
28
Symbol Table (SYMTAB)
29
Two Pass Assembler – Pass 2
30