Upload
kavyashree-jamadagni
View
213
Download
0
Embed Size (px)
Citation preview
7/29/2019 09 Assembly Example
1/16
Assembly Language Example
7/29/2019 09 Assembly Example
2/16
Todays Topics
owc ar s
Practice assembly programming
7/29/2019 09 Assembly Example
3/16
Flowcharts
ere are o er more sop s ca e me o s o represen ngprograms.
owc arts wor we or so tware wr tten n assem y co elevel.
e w see og ca u ng oc s n owc art ormats a ongwith assembly code templates.
7/29/2019 09 Assembly Example
4/16
Flowcharts
Meaning of symbols ere are many more sym o s o er an
these.Start or End
apes may e erent.
In this course, those four symbols areflow
pretty muc a we nee .Decision
Process
7/29/2019 09 Assembly Example
5/16
Flowcharts
If-Then-Elsee s or ec s on
Bxx Process A
Process B code
If(PillColor == RED)RealWorld
Color of Pillis RED?
TRUE
MatrixMatrix RealWorld
FALSE
l daa Pi l l Col orcmpa #RED
bne l mat r i xReal Wor l dbr a l ski p
l mat r i x: Mat r i xl ski p: . . .
7/29/2019 09 Assembly Example
6/16
Flowcharts
While-Doe s or ec s on
Bxx past BRA
Process code
BRA to Bxx
l daa KnowThi sl l oop: cmpa #YES
KnowThis? StudyMore
TRUE
FALSE
St udyMor el daa KnowThi s
br a l l ool next : Next St ep
7/29/2019 09 Assembly Example
7/16
Flowcharts
Repeat-Untilrocess co e
Set CCR bits
Bxx to Process codeDoSomething
Example:l oop: DoSomet hi ng
beq l donebr a l oop
Is the Jobdone?
FALSE
TRUE
7/29/2019 09 Assembly Example
8/16
Flowcharts
Bxx to Process 1Set CCR bitsBxx to Process 2
Case
Bxx to Process NDefault Process code
BRA past Process N codeProcess 1 code
nTemp
< 20 TurnOnHeater
TRUE
Process 2 codeBRA past Process N codeProcess N code
FALSE
nTemp< 70
FlashIndicatorTRUE
Example:l daa nTempcmpa #20bhs l 1
FALSE
nTem TRUE
br a l r esl 1: cmpa#70
bhi l 2
Fl ashI ndi cat or
< 100urn n oo er
FALSE
l 2: cmpa #100bhi l 3
TurnOnCool erbr a l r es
Alarm
l r es:
7/29/2019 09 Assembly Example
9/16
Flowchart Guidelines
o no re er o reg s ers n e owc ar
Arrows should never cross They will not need to if the flowchart represents a structured
program
e purpose s to remove any quest ons a out ow toprogram and understand the algorithm, and this usuallydetermines when the flowchart contains enough detail.
7/29/2019 09 Assembly Example
10/16
Assembly Example
onver an array o - y e g- n an va ues o an array oLittle-Endian values.
et
$1000 hold the address of the array of Big-Endian values,
$1002 hold the address of the array for the Little-Endian values,
$1004 hold the two-byte length of numbers to convert. Write an assembl ro ram to im lement these re uirements.
7/29/2019 09 Assembly Example
11/16
Start
1: Point to the first BE item
2: Point to the first LE item
3: Make a copy of the length
4. There are nomore elements
TRUE
5: Copy 1st BE byte to 4th LE byte
6: Co 2nd BE b te to 3rd LE b te
7: Copy 3rd BE byte to 2nd LE byte
9: Point to next elements & dec length
End
7/29/2019 09 Assembly Example
12/16
or g $1000Bend ds. w 1LEnd ds. w 1
Start
.
TmpLen ds. w 1or g $2000l dx BEnd
1: Point to the first BE item
2: Point to the first LE item
l dd Lengt hLoop std TmpLen ; 3
beq Done
3: Make a copy of the length
,st aa 3, y ; 2l daa 1, x ; 3st aa 2, y ; 2
4. There are nomore elements
TRUE
,
st aa 1, y ; 2l daa 3, x ; 3st aa 0, y ; 2
5: Copy 1st BE byte to 4th LE byte
6: Co 2nd BE b te to 3rd LE b te
i nxi nx
i nx
7: Copy 3rd BE byte to 2nd LE byte
i nyi nyi ny
9: Point to next elements & dec length
subd #$0001br a Loop
Done swiEnd
7/29/2019 09 Assembly Example
13/16
or g $1000Bend ds. w 1
Start
End s. wLengt h ds . w 1
or 2000
1: Point to the first BE item
2: Point to the first LE item l dx BEndl dy Lend
l dd Lengt h
3: Make a copy of the length
oop eq onemovb 0, x, 3, y ; 5movb 1, x, 2, ymovb 2 x 1
4. There are nomore elements
TRUE
movb 3, x, 0, yl eax 4, x ; 2l eay 4, y
5: Copy 1st BE byte to 4th LE byte
6: Co 2nd BE b te to 3rd LE b tesu ;br a Loop
Done swi
7: Copy 3rd BE byte to 2nd LE byte
9: Point to next elements & dec length
EndNote:Youcansave10(=3+2x2 +3)cycles.
7/29/2019 09 Assembly Example
14/16
Questions?
7/29/2019 09 Assembly Example
15/16
Wrap-up
What weve learned owc ar s
Templates will be greatly helpful.
ssem y program examp e
7/29/2019 09 Assembly Example
16/16
What to Come
r me c ns ruc ons
Logic instructions