Example of SIC Assembler Language Program
Example of SIC Assembler Language Program
Line
source statement
5
COPY START 1000
10
FIRST
STL
RETADR
15
CLOOP JSUB RDREC
20
LDA
LENGTH
25
COMP ZERO
30
JEQ
ENDFIL
35
JSUB WRREC
40
J
CLOOP
45
ENDFIL LDA
EOF
50
STA
BUFFER
55
LDA
THREE
60
STA
LENGTH
65
JSUB
WRREC
70
LDL
RETADR
75
RSUB
1/4
EOF
EOF = 0 ?
EOF = 0
(output record)
CLOOP
EOF3
EOF
(caller)
80
85
90
95
100
105
110
115
120
125
130
2/4
EOF
BYTE
CEOF
THREE
WORD 3
ZERO
WORD 0
RETADR RESW 1
LENGTH RESW 1
BUFFER RESB
4096
4096 byte
.
.
SUBROUTINE TO READ RECORD INTO BUFFER
.
()
RDREC LDX
ZERO
LDA
ZERO
AX0
135
140
145
150
155
160
165
170
175
180
185
190
RLOOP
TD
JEQ
RD
COMP
JEQ
STCH
TIX
JTL
EXIT
STX
RSUB
INPUT
BYTE
MAXLEN WORD
INPUT
RLOOP
INPUT
ZERO
EXIT
BUFFER,X
MAXLEN
RLOOP
LENGTH
XF1
4096
3/4
AX
(EOR=0)
(X)
4/4
195 .
200 .
SUBROUTINE TO WRITE RECORD INTO BUFFER
205 .
()
210 WRREC LDX
ZERO
215 WLOOP TD
OUTPUT
220
JEQ
WLOOP
225
LDCH BUFFER,X (X)
230
WD
OUTPUT
235
TIX
LENGTH
240
JLT
WLOOP
245
RSUB
Line
5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
Loc
1000
1000
1003
1006
1009
100C
100F
1012
1015
1018
101B
101E
1021
1024
1027
1/4
Source statement
object code
COPY
START 1000
FIRST
STL
RETADR
141033
CLOOP JSUB RDREC
482039
LDA
LENGTH
001036
COMP ZERO
281030
JEQ
ENDFIL
301015
JSUB WRREC
482061
J
CLOOP
3C1003
ENDFIL LDA
EOF
00102A
STA
BUFFER
0C1039
LDA
THREE
00102D
STA
LENGTH
0C1036
JSUB
WRREC
482061
LDL
RETADR
081033
RSUB
4C0000
80
85
90
95
100
105
110
115
120
125
130
102A
102D
1030
1033
1036
1039
.
.
.
2039
203C
EOF
THREE
ZERO
RETADR
LENGTH
BUFFER
BYTE
CEOF
WORD 3
WORD 0
RESW 1
RESW 1
RESB
4096
2/4
454F46
000003
000000
ZERO
ZERO
041030
001030
135
140
145
150
155
160
165
170
175
180
185
190
203F RLOOP
2042
2045
2048
204B
204E
2051
2054
2057 EXIT
205A
205D INPUT
205E MAXLEN
TD
JEQ
RD
COMP
JEQ
STCH
TIX
JTL
STX
RSUB
BYTE
WORD
INPUT
RLOOP
INPUT
ZERO
EXIT
BUFFER,X
MAXLEN
RLOOP
LENGTH
XF1
4096
E0205D
30203F
D8205D
281030
302057
549039
2C205E
38203F
101036
4C0000
F1
001000
3/4
195
200
205
210
215
220
225
230
235
240
245
250
255
4/4
.
.
SUBROUTINE TO WRITE RECORD INTO BUFFER
.
2061 WRREC LDX
ZERO
041030
2064 WLOOP TD
OUTPUT
E02079
2067
JEQ
WLOOP
302064
206A
LDCH BUFFER,X
509039
206D
WD
OUTPUT
DC2079
2070
TIX
LENGTH
2C1036
2073
JLT
WLOOP
382064
2076
RSUB
4C0000
2079 OUTPUT BYTE X05
05
END
FIRST
Assembler language
program (Fig.2.1)
Algorithm of assembler
(Fig.2.4)
Object program
(Fig.2.3)
begin
read first input line
if OPCODE = 'START' then
begin
save #[OPERAND] as starting address
initialize LOCCTR to starting address
write line to intermediate file
read next input line
end {if START}
else
initialize LOCCTR to 0
LOCCTR=1000
Fig.2.1
Fig.2.4(a)
10
FIRST
Fig.2.1
STL RETADR
(FIRST,1000)
LOCCTR=1003
Fig.2.4(a)
Fig.2.1
(CLOOP,1003)
LOCCTR=1006
Fig.2.4(a)
20
LDA
LENGTH
Fig.2.1
LOCCTR=1009
LDA
Fig.2.4(a)
LENGTH
Intermediate file
80
85
90
(EOF , 102A)
LOCCTR=102D
(THREE ,102D)
LOCCTR=1030
(ZERO , 1030)
LOCCTR=1033
EOF
BYTE
THREE WORD
ZERO WORD
CEOF
3
0
Fig.2.1
EOF
BYTE
THREE WORD
ZERO WORD
Fig.2.4(a)
CEOF
3
0
Intermediate file
5
10
.
(RETADR , 1033)
.
intermediate
Pass 2 :
begin
read first input line {from intermediate file}
if OPCODE = 'START' then
begin
end{if start}
write Header record to obect program
initialize first Text record
while OPCODE 'END' do
Fig2.4(b)
..
write listing line
read next input line
end {while}
write last Text record to object program
end {pass 2}
5
10
file
HCOPY--00100000107A
T 001000__141033
RETADR 141033
Fig2.2
Assembler language
program (Fig.2.1)
Algorithm of assembler
(Fig.2.4)
Object program
(Fig.2.3)
Pass 2
Fig2.4(b)
SYMTAB
(LOCCTR-starting address)
= length
Pass 2
Fig2.4(b)
Instruction Table
SYMTAB
( LABEL LOCCTR )
RETADR 1033
141033
454F46
Pass 2 Fig2.4(b)
else if OPCODE = 'BYTE' or 'WORD' then
convert constant to object code
000003
F1
Pass 2 Fig2.4(b)
4096 = 212
001000
Source statement
END
FIRST
Pass 2
Fig2.4(b)
SYMTAB
( LABEL LOCCTR )
FIRST 1000
E 001000
Fig 2.3
95 RETADR RESW
1
# : immediate addressing mode
55
LDA #3
+ : extended instruction format
15 CLOOP +JSUB
RDREC
Memory
I/O
0006
1036-0009
=102D >1000
125 1036
CLOOP +JSUB
RDREC
.
.
RDREC
CLEAR X
n i x b p e ..
000101
1
11 0 0 1 0 ..
7
000A
LDA
LENGTH
STX
LENGTH
000A
LDA
LENGTH
STX
LENGTH
15 CLOOP +JSUB
RDREC
M 000007 05
0000
.
0006 4B101036 (CLOOP +JSUB RDREC)
.
.
(RDREC CLEAR X)
B410
1036
.
.
4B101036
0007
4B106036
M 000007 05
5000
.
5006 4B106036
.
.
B410
6036
.
.
Fig 2.7
RDREC
M 000007 05
(5*4=20 bits )
J
STCH
CLOOP
BUFFER,X
RDREC M 000007 05
WRREC M 000014 05
WRREC M 000027 05
2.3 Machine-independent
assembler features
2.3 Machine-independent
assembler features
(1)Immediate addressing : the operand is
assembled as part of the machine
instruction.
Literal addressing : the operand value is
specified as a constant at some other
memory location.
2.3 Machine-independent
assembler features
(2)LITTAB (literal table):
Pass 1: literal->LITTAB->LTORG->address
Pass 2: literal->LITTAB->address
2.3 Machine-independent
assembler features
(3)Why use EQU?
*It is used for improved readability in place
of numeric values.
*It is used for defining mnemonic names
for registers.
*It is used to have the standard register
mnemonic built into the assembler.
2.3 Machine-independent
assembler features
(4)Why use ORG?
*It assigns values to symbols.
*It is used in label definition.
*Restriction: it must have been defined
previously in the program.
2.3 Machine-independent
assembler features
(5)Expressions are classified as either absolute
expressions or relative expressions depending upon
the type of value they produce.
*Absolute expressions: relative terms occur in pairs.
*Relative expressions: the remaining unpaired
relative term must have a positive sign.
*Example:
RETADR(R),BUFFER(R),BUFEND(R),MAXLEN(A).
2.3 Machine-independent
assembler features
(6)Program locks allow the generated
machine instructions and data to appear in
the object program in a different order from
the corresponding source statements.
2.3 Machine-independent
assembler features
(7)The assembler directive USE indicates
which portions of the source program
belong to the various blocks.
2.3 Machine-independent
assembler features
(8)During pass 1, a separate location counter for each program
block and each label in the program is assigned an address
that in relative to the start of the block that contains it.
Block name Block number Address Length
(default)
0
0000 0066
CDATA
1
0066 000B
CBLKS
2
0071 1000
Example:
20 0006 0 LDA LENGTH 032 ???
operand (LENGTH)=0003
start address of program block 1 (CDATA)=0066
->Target address=0003+0066=0069
->Since pc relative addressing, the required
displacement=0069-0009=0060->???=060
2.3 Machine-independent
assembler features
(9)The separation of the program into blocks
has considerably reduced the addressing
problems.
HCOPY...
T000000...
T00001E...
T000027...
T000044...
T00006C...
T00004D...
T00006D...
T000000...
2.3.5
Control sections
and program linking
1/7
2/7
3/7
4/7
(4)Example:
(Fig 2.16)
5/7
BUFEND-BUFFER
6/7
7/7
2.4
Assembler design options
1/8
2/8
3/8
4/8
5/8
6/8
7/8
8/8