Assembly Language
g g Example
Todays Topics
Fl
Flowcharts
h t
Flowcharts
Flowcharts
Fl
h t work
k well
ll ffor software
ft
written
itt in
i assembly
bl code
d
level.
We will
W
ill see llogical
i lb
building
ildi
bl
blocks
k iin fl
flowchart
h
fformats along
l
with assembly code templates.
Flowcharts
Meaning of symbols
Sh
Shapes
may be
b different.
diff
t
Start or End
flow
Decision
Process
Flowcharts
If-Then-Else
Sett CCR bit
S
bits ffor decision
d i i
Bxx Process A
Process B code
Color of Pill
is RED?
TRUE
FALSE
Matrix
RealWorld
If(PillColor == RED)
RealWorld
Else
Matrix
Example:
ldaa
PillColor
cmpa
#RED
bne
lmatrix
RealWorld
bra
lskip
lmatrix: Matrix
lskip: ...
Flowcharts
While-Do
Sett CCR bit
S
bits ffor decision
d i i
Bxx past BRA
Process code
Set CCR bits for decision
BRA to Bxx
KnowThis?
TRUE
FALSE
S
StudyMore
Example:
ldaa
KnowThis
lloop: cmpa
#YES
beq
lnext
StudyMore
ldaa
KnowThis
bra
lloop
p
lnext: NextStep
Flowcharts
Repeat-Until
Process code
P
d
Set CCR bits
Bxx to Process code
DoSomething
Is the Job
done?
TRUE
FALSE
Example:
loop: DoSomething
ldaa
Result
beq
ldone
bra
loop
ldone:
Flowcharts
Case
nTemp
< 20
TRUE
TurnOnHeater
FALSE
nTemp
< 70
TRUE
FlashIndicator
FALSE
nTemp
< 100
FALSE
Alarm
TRUE
T
TurnOnCooler
O C l
Process N code
Example:
ldaa nTemp
cmpa #20
bhs
l1
TurnOnHeater
bra
lres
l1: cmpa #70
bhi
l2
FlashIndicator
bra
lres
l2:
cmpa #100
bhi
l3
TurnOnCooler
bra
lres
l3: Alarm
lres:
Flowchart Guidelines
D nott refer
Do
f to
t registers
i t
in
i the
th flowchart
fl
h t
The purpose is
Th
i to
t remove any questions
ti
about
b th
how to
t
program and understand the algorithm, and this usually
determines when the flowchart contains enough detail.
Assembly Example
L t
Let
Write an assembly
yp
program
g
to implement
p
these requirements.
q
Start
4. There are no
more elements
FALSE
5: Copy 1st BE byte to 4th LE byte
6: Copy 2nd BE byte to 3rd LE byte
7: Copy 3rd BE byte to 2nd LE byte
8: Copy 4th BE byte to 1st LE byte
9: Point to next elements & dec length
End
TRUE
Start
Bend
LEnd
Length
TmpLen
4. There are no
more elements
Loop
TRUE
FALSE
5: Copy 1st BE byte to 4th LE byte
6: Copy 2nd BE byte to 3rd LE byte
7: Copy 3rd BE byte to 2nd LE byte
8: Copy 4th BE byte to 1st LE byte
9: Point to next elements & dec length
End
Done
org
ds.w
ds.w
ds w
ds.w
ds.w
org
ldx
ldy
ldd
std
beq
ldaa
staa
ldaa
staa
ldaa
staa
ldaa
staa
inx
inx
inx
inx
iny
iny
iny
iny
ldd
subd
bra
swi
$1000
1
1
1
1
$2000
BEnd
Lend
Length
TmpLen
Done
0 x
0,x
3,y
1,x
2,y
2 x
2,x
1,y
3,x
0,y
; 3
;
;
;
;
;
;
;
;
;
3
2
3
2
3
2
3
2
1
; 1
TmpLen
#$0001
Loop
; 3
Start
org
Bend
ds.w
LEnd
ds.w
Length ds.w
4. There are no
more elements
TRUE
Loop
FALSE
5: Copy 1st BE byte to 4th LE byte
6: Copy 2nd BE byte to 3rd LE byte
7: Copy 3rd BE byte to 2nd LE byte
Done
org
ldx
ldy
ldd
beq
movb
movb
movb
movb
leax
leay
subd
bd
bra
swi
$1000
1
1
1
$2000
BEnd
Lend
Length
Done
0,x,3,y ; 5
1,x,2,y
2,x,1,y
3,x,0,y
4,x
; 2
4,y
#1
; 2
Loop
End
Note:Youcansave10(=3+2x2 +3)cycles.
Questions?
Wrap-up
What weve learned
Fl
Flowcharts
h t
A
Assembly
bl program example
l
What to Come
A ith ti instructions
Arithmetic
i t
ti
Logic instructions