Sample Assembly Processing
source module
1 title sample1
2 ; this is a sample hand assembly
3 set offset,55
4 loop: lda 0xc000
5 cmp (third),y
6 beq loop
7 extern outside
8 set offset,040
9 down: sta 0x0400
10 clc
11 adc #01
12 bne down
13 go: entry loop,down,first
14 jmp loop
15 first: word loop-down
16 second: byte 01
17 third: byte 7,0xbc,outside
18 fourth: word 0x1000
19 end
Pass1 processing
initialize location counter (lc)
1 (0) nothing (but title has to be the first source line)
2 (0) nothing
3 (0) enter "offset" into symbol table (ST) with a value of 55,a
4 (0) enter "loop" into ST with a value of 0,r
increment lc by 3
5 (3) increment lc by 2
6 (5) increment lc by 2
7 (7) enter "outside" into ST with a value of 0,ue
8 (7) change "offset's" value in ST to 040,a
9 (7) enter "down" into ST with a value of 7,r
increment lc by 3
10 (10) increment lc by 1
11 (11) increment lc by 2
12 (13) increment lc by 2
13 (15) enter "go" in ST with a value of 15,r
Note: loop and down are entry points
enter first into ST
14 (15) increment lc by 3
15 (18) give "first" a value of 18,r in ST
increment lc by 2
16 (20) enter "second" in ST with a value of 20,r
increment lc by 1
17 (21) enter "third" in ST with a value of 21,r
increment lc by 3
18 (24) enter "fourth" in ST with a value of 24,r
increment lc by 2
19 (26) print ST
Symbol Table at the end of Pass1
symbol value/mode defined by set entry point
offset 040,a T F
loop 0,r F T
outside 0,ue F F
down 7,r F T
go 15,r F F
first 18,r F T
second 20,r F F
third 21,r F F
fourth 24,r F F
Pass2 processing
reset lc to 0
1 (0) Initialize Object Module (OM) ( magic number = 0x107,...)
enter "sample1" as first entry in string area
write source listing of line 1
2 (0) write source listing of line 2
3 (0) change "offset's" value in ST to 55,a
write source listing of line 3
4 (0) opcode = AD (absolute addressing)
op1 = C000 (address)
increment lc by 3
write source listing of line 4
5 (3) opcode = D1 (indirect indexed addressing)
op1 = [21,r] = 0x15
make relocation entry -->
address = 4
ordinal = 0 (doesn't matter)
relative = true (1)
length = 0 (byte)
external reference = false (0)
increment lc by 2
write source listing of line 5
6 (5) opcode = F0 (relative addressing)
op1 = [0,r - 7,r = -7,a] = F9
increment lc by 2
write source listing of line 6
7 (7) write source listing of line 7
8 (7) change "offset's" value in ST to 040,a
write source listing of line 8
9 (7) opcode = 8D (absolute addressing)
op1 = 0400 (address)
increment lc by 3
write source listing of line 9
10 (10) opcode = 18
increment lc by 1
write source listing of line 10
11 (11) opcode = 69 (immediate addressing)
op1 = 01 (data)
increment lc by 2
write source listing of line 11
12 (13) opcode = D0 (relative addressing)
op1 = [7,r - 15,r = -8,a] = F8
increment lc by 2
write source listing of line 12
13 (15) write source listing of line 13
14 (15) opcode = 4C (absolute addressing)
op1 = [0,r] = 0x0000
make relocation entry -->
address = 16
ordinal = 0 (doesn't matter)
relative = true (1)
length = 1 (word)
external reference = false (0)
increment lc by 3
write source listing of line 14
15 (18) op1 = [0,r - 7,r = FFF9,a] 0xFFF9
increment lc by 2
write source listing of line 15
16 (20) op1 = 01
increment lc by 1
write source listing of line 16
17 (21) op1 = 07
op2 = BC
op3 = 00
make relocation entry -->
address = 23
ordinal = 1
relative = false (0)
length = 0 (byte)
external reference = true (1)
increment lc by 3
write source listing of line 17
18 (24) op1 = 0x1000
increment lc by 2
write source listing of line 18
19 (26) dump ST into OM
fill in sizes in OM
package up OM
write source listing of line 19
source listing
file: prog1
loc obj rep line source
--- ------- ---- ------
0000| 1| title sample1
0000| 2| ; this is a sample hand assembly
0000| 3| set offset,55
0000|AD 00 C0 4| loop: lda 0xc000
0003|D1 15 5| cmp (third),y
0005|F0 F9 6| beq loop
0007| 7| extern outside
0007| 8| set offset,040
0007|8D 00 04 9| down: sta 0x0400
000A|18 10| clc
000B|69 01 11| adc #01
000D|D0 F8 12| bne down
000F| 13| go: entry loop,down,first
000F|4C 00 00 14| jmp loop
0012|F9 FF 15| first: word loop-down
0014|01 16| second: byte 01
0015|07 BC 00 17| third: byte 7,0xbc,outside
0018|00 10 18| fourth: word 0x1000
001A| 19| end
object module
header area
magic number = 0x107
size of text area = 26
size of data area = 0
size of bss area = 0
size of OMST = 4 * 12 = 48
size of text relocation area = 3 * 8 = 24
size of data relocation area = 0
text area
AD 00 C0 D1 15 F0 F9 8D
00 04 18 69 01 D0 F8 4C
00 00 F9 FF 01 07 BC 00
00 10
relocation area
address external length relative ordinal
------- -------- ------ --------- ------
4 0 0 1 0
16 0 1 1 0
23 1 0 0 1
object module symbol table
symbol name (offset) type value
-------------------- ---- -----
loop (12) text (4) 0
outside (17) undef,ext (1) 0
down (25) text (4) 7
first (30) text (4) 18
string area
length = 36
sample1,loop,outside,down,first
© Douglas J. Ryan
Douglas J. Ryan/ryandj.pacificu.edu