Disassembly of 9S12 Op Codes Writing An Assembly Language Program
Disassembly of 9S12 Op Codes Writing An Assembly Language Program
EXAMPLE:
if (A<10)
{
var = 5;
}
CMPA
#10
BLT
L1
BRA
L2
L1: LDAB #5
STAB
var
L2: next instruction
OR:
L2:
CMPA
#10
BGE
L2
LDAB
#5
STAB
var
next instruction
L1:
L2:
CMPA
#10
BLT
L1
CLR
VAR
BRA
L2
LDAB
#5
STAB
var
next instruction
EXAMPLE:
i = 0;
do
{
table[i]=table[i]/2;
i=i+1;
}
while (i <= LEN);
LDX
CLRA
L1: ASR
INCA
CMPA
BLE
#table
1,X+
#LEN
L1
EXAMPLE:
i = 0;
while( i <= LEN)
{
table[i]=table[i]*2;
i=i+1;
}
LDX
#table
CLRA
L1: CMPA
#LEN
BLT
L2
BRA
L3
L2: ASL
1,X+
INCA
BRA
L1
L3: next instruction
4. Strategy: Because we are using a table of data, we will need pointers to each table so
we can keep track of which table element we are working on.
Use the X and Y registers as pointers to the tables.
5. Use a simple flow chart to plan structure of program.
l1:
org
ldaa
ldx
ldy
ldab
lsrb
stab
inx
iny
deca
$1000
$2000
5
prog
#count
#table1
#table2
0,x
0,y
bne l1
swi
org data
table1: dc.b $07,$c2,$3a,$68,$F3
table2: ds.b count
9. Advanced: Optimize program to make use of instructions set efficiencies:
; Program to divide a table by two
; and store the results in memory
prog: equ
data: equ
count: equ
l1:
$1000
$2000
5
org prog
ldaa #count
ldx
#table1
ldy
#table2
ldab 1,x+
lsrb
stab 1,y+
dbne a,l1
swi
org data
table1: dc.b $07,$c2,$3a,$68,$F3
table2: ds.b count
TOP-DOWN PROGRAM DESIGN
Plan data structures in memory
Start with a large picture of the program structure
Work down to more detailed structure
Translate structure into code
Optimize for efficiency
DO NOT SACRIFICE CLARITY FOR EFFICIENCY