System Software 2
System Software 2
Chapter 2: Assemblers
Assemblers
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
2
System Programming, Spring 2010
Deparrtment o Outline
3
System Programming, Spring 2010
Deparrtment o
Assembler Directives
4
System Programming, Spring 2010
Deparrtment o
A SIC Assembly
y Program
g Example
p
[ Figure 2.1 ]
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
5
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
6
System Programming, Spring 2010
Deparrtment o Outline
7
System Programming, Spring 2010
Deparrtment o
1
1. Convert mnemonic operation codes to their machine
of Electrrical Engineering,, Feng-Ch
8
System Programming, Spring 2010
Deparrtment o
Program
g from Figure
g 2.1 with Object
j Code
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity [ Figure 2.2 ]
9
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
10
System Programming, Spring 2010
Deparrtment o Object Program Format
Column Contents
of Electrrical Engineering,, Feng-Ch
1 H
Header 2-7 Program name
Record 8-13 Starting address of object program (HEX)
14-19 Length of object program in bytes (HEX)
1 T
Text 2-7 Starting address for object code in this record (HEX)
Record 8-9 Length of object code in this record in bytes (HEX)
10-69 Object code (HEX, 2 columns per byte of object code)
1 E
End
Record 2-7 Address off first
f executable instruction in object program
hia Unive
(HEX)
ersity
11
System Programming, Spring 2010
Deparrtment o
Object
j Program
( Corresponding to Figure 2.2 )
[ Figure 2.3 ]
of Electrrical Engineering,, Feng-Ch
hia Unive
12
System Programming, Spring 2010
Deparrtment o Two-pass
Two pass SIC Assembler
13
System Programming, Spring 2010
Deparrtment o
Outline
14
System Programming, Spring 2010
Deparrtment o Data Structures
15
System Programming, Spring 2010
Pass 1
Deparrtment of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
16
System Programming, Spring 2010
Pass 2
Deparrtment of Electrrical Engineering,, Feng-Ch
Complete!
hia Unive
ersity
17
System Programming, Spring 2010
Deparrtment o
Outline
18
System Programming, Spring 2010
Deparrtment o
A SIC/XE Assembly Program Example
SIC ( Figure 2.1 ) SIC/XE ( Figure 2.5 )
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
19
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
20
System Programming, Spring 2010
Deparrtment o Outline
21
System Programming, Spring 2010
Deparrtment o
22
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
SUBROUTINE TO READ RECORD INTO BUFFER
23
System Programming, Spring 2010
Deparrtment o
Addressing
24
System Programming, Spring 2010
Deparrtment o
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity Example 1: PC Relative Addressing
25
System Programming, Spring 2010
Deparrtment o
26
System Programming, Spring 2010
Deparrtment o Base Relative Addressing
Difference between PC-relative and Base-relative
of Electrrical Engineering,, Feng-Ch
addressing
The assembler knows what the contents of the Program Counter
will be at execution time. Base register ?
The base register is under control of the programmer. Therefore,
the programmer must tell the assembler what the base register
will contain during execution of the program
Assembler Directives
BASE Informs the assembler that the base register will contain
the address of #[Operand]
NOBASE IInforms
f the
th assembler
bl th
thatt th
the contents
t t off the
th base
b
hia Unive
27
System Programming, Spring 2010
Deparrtment o
28
System Programming, Spring 2010
Deparrtment o Outline
29
System Programming, Spring 2010
Deparrtment o
Program Relocation
Multiprogramming
of Electrrical Engineering,, Feng-Ch
Absolute Programs
Must be loaded at exact address in order to execute
properly
Relocatable Programs
Can be loaded into memory wherever these is room,
hia Unive
30
System Programming, Spring 2010
Deparrtment o
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity Examples of Program Relocation
31
System Programming, Spring 2010
Deparrtment o
33
System Programming, Spring 2010
Deparrtment o
Outline
34
System Programming, Spring 2010
Deparrtment o
Additional assembler features
Figure 2.5 Figure 2.9
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
35
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
36
System Programming, Spring 2010
Deparrtment o Outline
37
System Programming, Spring 2010
Deparrtment o
Literals (1/3)
38
System Programming, Spring 2010
Deparrtment o Literals (2/3)
39
System Programming, Spring 2010
Deparrtment o
Literals (3/3)
Mostt assemblers
M bl recognize
i duplicate
d li t litliterals
l and
d store
t only
l
one copy of the specified data value.
By comparison of the character strings defining them.
hia Unive
EX: the literal =X’05’ ( Figure 2.9, Line 215 and 230 )
EX: =C’EOF’ and =X’454F45’ ?
ersity
40
System Programming, Spring 2010
Deparrtment o The implementation of literals
Pass1:
Search and update LITTAB for the specified literal name
When encounters a LTORG statement or the end of the program,
the assembler makes a scan of the LITTAB and assigns an
address for all unallocated literals
Update the location counter to reflect the number of bytes
p
occupied by
y each literal
Pass2:
Search LITTAB for the address of each literal encountered
hia Unive
41
System Programming, Spring 2010
Deparrtment o
Outline
42
System Programming, Spring 2010
Deparrtment o EQU assembler directive
43
System Programming, Spring 2010
Deparrtment o
A EQU 0
X EQU 1
L EQU 2
INDEX EQU X
hia Unive
BASE EQU B
FLOAT EQU F
ersity
44
System Programming, Spring 2010
Deparrtment o ORG assembler directive
Example:
SYMBOL is 6-byte, VALUE is 1-word, and FLAGS is 2-byte
hia Unive
ersity
45
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
46
System Programming, Spring 2010
Deparrtment o Restrictions
EQU:
of Electrrical Engineering,, Feng-Ch
ORG:
all symbols used to specify the new location counter value
must have been previously defined.
hia Unive
ersity
47
System Programming, Spring 2010
Deparrtment o
Outline
48
System Programming, Spring 2010
Deparrtment o Expressions
Expression Terms
hia Unive
49
System Programming, Spring 2010
Deparrtment o
Absolute Expressions
of Electrrical Engineering,, Feng-Ch
R l ti E
Relative Expressions
i
Contains an odd number of relative terms, with one more
positive terms than negative terms
hia Unive
50
System Programming, Spring 2010
Defining Symbol Types in the
Deparrtment o
S
Symbol
b l T
Table
bl
To determine the type of an expression,
expression we must keep track of the
of Electrrical Engineering,, Feng-Ch
For this purpose we need a flag in the symbol table to indicate type
of value (absolute or relative) in addition to the value itself.
hia Unive
With this information the assembler can easily determine the type of
each expression used as an operand and generate Modification
records in the object program for relative values
values.
ersity
51
System Programming, Spring 2010
Deparrtment o
Outline
52
System Programming, Spring 2010
Deparrtment o Program Blocks vs.
vs Control Sections
Program Blocks
of Electrrical Engineering,, Feng-Ch
Control Sections
Refer to segments that are translated into independent
object program units
hia Unive
ersity
53
System Programming, Spring 2010
Deparrtment o
Program Blocks
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
54
System Programming, Spring 2010
Deparrtment o Program Blocks (1/2)
55
System Programming, Spring 2010
Deparrtment o
E h program bl
Each k may actually
block t ll contain
t i severall separate
t
segments of the source program. The assembler will (logically)
rearrange these segments to gather together the pieces of
each block.
hia Unive
ersity
56
System Programming, Spring 2010
Deparrtment o
Program
g from Fig.
g 2.11 with object
j code
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity [ Figure 2.12 ]
57
System Programming, Spring 2010
58
System Programming, Spring 2010
Deparrtment o The implementation of Program Blocks (1/2)
Pass 1
of Electrrical Engineering,, Feng-Ch
blocks.
( see next page )
ersity
59
System Programming, Spring 2010
Deparrtment o
Pass 2
The address for each symbol relative to the start of the
object program is easily found from the information in
SYMTAB.
The assembler simply adds the location of the symbol
symbol,
hia Unive
60
System Programming, Spring 2010
Deparrtment o
Object
j Program
g
( Corresponding to Figure 2.11 )
[ Figure 2.13 ]
of Electrrical Engineering,, Feng-Ch
Default(1)
( )
Default(2)
CDATA(2)
Default(3)
CDATA(3)
hia Unive
ersity
61
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
62
System Programming, Spring 2010
Deparrtment o Outline
63
System Programming, Spring 2010
Deparrtment o
Assembler Directives
<symbol> CSECT
of Electrrical Engineering,, Feng-Ch
64
System Programming, Spring 2010
Deparrtment o
Control Section : COPY
[ Figure 2.16 ]
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
65
System Programming, Spring 2010
Deparrtment o
66
System Programming, Spring 2010
Deparrtment o
Control Section : WRREC
[ Figure 2.16 ]
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
67
System Programming, Spring 2010
Deparrtment o
1 D
Define 2-7 Name of external symbol defined in this control section
Record 8 13
8-13 Relative address of symbol within this control section (HEX)
14-73 Repeat information in Col. 2-13 for other external symbols
1 R
Refer
27
2-7 N
Name off external
t l symbol
b l referred
f d tto iin thi
this control
t l section
ti
Record
8-73 Names of other external reference symbols
1 M
2-7 Starting address of the field to be modified, relative to the
beginning of the program (HEX)
Mod.
8-9 Length of the field to be modified, in half-bytes (HEX)
eco d
Record
10 Modification flag (+ or -)
hia Unive
68
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
69
System Programming, Spring 2010
Deparrtment o
Outline
70
System Programming, Spring 2010
Deparrtment o Outline
71
System Programming, Spring 2010
Deparrtment o
One-Pass
One Pass Assemblers
Eli i t fforward
Eliminate d references
f
Data items are defined before they are referenced.
But,, forward references to labels on instructions cannot be
eliminated as easily.
Prohibit forward references to data items.
72
System Programming, Spring 2010
Deparrtment o
Sample
p program
p g for a one-pass
p assembler
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity [ Figure 2.18 ]
73
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
74
System Programming, Spring 2010
Deparrtment o Load-and-Go
Load and Go Assemblers (1/2)
i t ti operand
If an instruction d is
i a symbol
b l th
thatt h
has nott yett b
been
defined, the operand address is omitted when the instruction is
assembled.
( Cont.)
ersity
75
System Programming, Spring 2010
Deparrtment o
Load-and-Go
Load and Go Assemblers (2/2)
76
System Programming, Spring 2010
Deparrtment o
Object code in memory and symbol table entries
of Electrrical Engineering,, Feng-Ch
hia Unive
ersity f program in
for i Fig.
Fi 2.18
2 18 after
ft scanning
i line
li 40
77
System Programming, Spring 2010
Deparrtment o
78
System Programming, Spring 2010
Deparrtment o Object Program Output Assemblers
79
System Programming, Spring 2010
Deparrtment o
80
System Programming, Spring 2010
Deparrtment o Outline
81
System Programming, Spring 2010
Deparrtment o
Multi-Pass
Multi Pass Assemblers
82
System Programming, Spring 2010
Deparrtment o Multi-Pass
Multi Pass Assemblers
83
System Programming, Spring 2010
Deparrtment of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
84
System Programming, Spring 2010
System Programming, Spring 2010
86
Deparrtment of Electrrical Engineering,, Feng-Ch
hia Unive
ersity Deparrtment of Electrrical Engineering,, Feng-Ch
hia Unive
ersity
System Programming, Spring 2010
88
Deparrtment of Electrrical Engineering,, Feng-Ch
hia Unive
ersity Deparrtment of Electrrical Engineering,, Feng-Ch
hia Unive
ersity