ED 3 - Compressed
ED 3 - Compressed
•Algorithm
- Set RS I and RSO (PSW .4 and PSW .3)
, This Mltocta Bank 3.
• lnhlallse A w1lb the value 7Sl-l.
• lnlllllll&e D whh th~ value l llt
• DJv!de A by D. A aats the quotlcnt, B gc111 the mmolnder.
• St~ A lnto 'RO.
• Store B inla Rt.
... Progqm
SBTB PSW,4 , RS'I • 1
SBTB PSW.3 ; RSO • I. 'fhlR scloots Bank 3,
MOV A. #75H : A._ 7SH
MOV B. #12H :D.-.t2H
DJV AB ; B, A (- A+ B
MOV RO,A ; RO c- A (quollcnO
MOV Rl. B ; R1 ._ B (l'OJMlndor)
Here: SJMP Herc ; Bnd the program.
_. Wrtte • Pf08'MI to add th• oontanta of locetlon 20H and 21H. Store reault at 22H (1um) and UH
(aany).
• Alao,tlhm
• lnitiallsc R2 with OOH (will bold lhe CJUTY later).
• Load cootcnta of 20H Into A rcglstor.
• Add conten.ta of 21 H 1nl'o A register.
• Chock the cany Oq.
• lf CP-0 then skip
Bise lncnm10nt R2
.-4 S.4tlll~' SIWJ ,_..,,.
. i 8-1,; i
.... Nalit:
~ W' la de A .g wlh EJdw.nal RAM
rerMfflber 1W folOwlng J&l t'dl onl l:
LW •tlll ¥1_ ,_ap ahl larl llltD f'il\ .
I) We n at- a.a ta. tllw -,na D11
caa ,t . , _ . , _... dlla f'tolo ltall
lffla l RAM.
ll n. .II MO VX llul IID ADDX ar SUIIX. We
.•
»sH t o ~ ~t i°" ' st:.rti"'S at '°H
!
--'• --
F, ~ RAM louti°"-S ~rt i"S .t
_ , _ ______________.__ ___
____________________..,._, ___ ___ -·-----·-----
afer a blo ck of 1o byt a• from loca
tlon 20H to loca tion 30H.
• Wrtt. • pro gra m to tran
n- Alg orit hm
• Initialise RO with ~OH (source r,ointer)
ter)
• Initialise R 1 with 30H (~n ati on poin
)
• lnitialilC R 7 •'ith OAH (count: J0d m 0AH
• Tak e data poi nu. l by RO into A.
• SIDre A al loc:ation pointed by Rl .
tions.
• IDCl'CIDCrll RO and RI to point to ncxr loca
s 0.
• Docremeot R7 and rep e.t till R7 become
ar Program
MO Y R0 ,#2 08 ;R0 4-2 0H
DC ltO ~lt04-R0 ♦ I
.,....
INC Ill ;RI +-R I+ 1
; IAap lill R7 bec oaw 0
ila dl be ~
~~--
• - ) ; i ~ R\)'fli~ !\.)ff_(~.llf ~~,
3
• JrritruiseOPTR.~~(~'ll~)
• ~ "Rl with C\..\H (~imtC 100-= t'l4Ji)
• ~~f'~byROml\.lA..
• Sh.YCA.•l.~p..-iakd~DPI'R..
• "b=:i"lYtPI RO -.1. DPT'R l0 p.NDi ro mte1l ~~
• ~Rl-.ltt-ptitl.\ill'R.1~,~(l
•PN,g.www
MOV RQ.D.18 ;RO~~
MO\' DPTR..Clffl .; ~ ~ ~
MOV Rl,AlAH :Rl+-tlAH
k t NOV .A..@RO ~A~(RO)
NOVX @DPl'R..A :[DPmJ~ A
INC RO ;R04-R.0+ l
~ DPl1t ;DPl'Rt--DPIR+ l
DIMZ Rl,_Bac:k :L<q.lillR'1~0
~S.INP Hl:le ;Eaddwzpd)CI.....
.;.JW f;a"tl 1
Mk:!OCOnlrollera & llcaltone MlJ-Sem. 6-E&TC)
2-63
a_ 2 -4.7 Program for
Block Transfer (Ex t RAM to Int
RAM)
...
• Write • pro gra m to tranafer a blo
Program
ck of 1 o by t•• fro m loc atio n 200 0H to loc atio n
20H.
MO VR 0,# 2.0 H
;RO +- 20H
MO V D17I"R #20 00H
; DPTR +- 200 0H
MO V R(7. #OAH
; R7 +-0 AH
Ba ck: MO VX A.@
D1 7fR ; A +- [DP TR ]"
MO V@ R0 ,A
; [RO] +-A
IN CR 0
; RO +-R O+ 1
IN CD PI' R
;D PT R~ DP TR + 1
DI NZ R7 . Ba ck
; Loo p till R7 becomes 0
He re: SJM PH ere
; End the program.
'a.. 2.4 .8 Pro gra m for Blo ck Tra nsf
er (Ex t RA M to Ex t RAM)
• Wr ite • pro gra m to tra nsf er •
blo ck of 200 bytes fro m loc atio
n 514 0H to loc atio n 9384H.
ea Alg ori thm
d': program
MOV RI. #51H
MOV R0,#40H ; RI, RO+- 5140H
Mov· R3, #93H
MOV R2, #84H ; R3, R2 +- 9384H
MOV R7,#0C8H ; R7 +-C8H
Back: MOV DPH.Rl
MOV DPL. RO ; DPTR points to source
MOVXA. @DPTR ; A gets source data
INC DPrR ; DPTRhas next source address
MOV Rl, DPH
MOV RO, DPL ; Rt, R0gct next source address
MOV DPH,R3
MOV DPL, R2 ; DPTR points to destination
MOVX @DPI"R,A ; A stores the data at destination
INC DPfR ; DPTRhas next destination address
.
MOV R3,DPH
MOV R2.DPL ; R3, R2gct next destination address
INC DPfR : DPTR~ DPTR+ 1
DJNZ R7, Back ; Loop till R7 becomes 0 ,.
I
• Algortthm
• Initialise R2 with OOH (will bold the carry later).
• Tab lower byte of 1• number from 20H into A register.
•
• Add lower byte of 2111J number from 22H to A register.
• Perform BA A on dlil resulL
• Store adjusted result lower byte from A to 24,H
• Tab higher byte of 111 Dvmba- from 21H into A resister.
--' MattNl1lUI' ft r
• Add with cany higher b)1t of 2., number Crom 23111<' A reJlstet.
• Pcrfonn DA A on this ~qalL
• Store adju.~tN result hightr byte from Ato 25H
• O.CCk lhc carry flag for final C8J1')'.
• UCF=O then nip
Ebe Increment R2
• Now R2 tw the carry.
• Store R2 at 26H
ir ~ram
• Write a program to convert a Packed BCD number stored at 20H Into unpacked BCD.
Siona result at 21H (lower byte) and 22H (higher byte),
a- Algorfthm
• ., Get the number from 20H into A register (E.g.: 75).
• AND with OFH to clear higher nibble (E.g.: 05).
• Store A at 21H.
• Apin gel lhe number from 20H into A register (E.g.: 75).
• AND with RJH to clear lower nibble (B.g.: 70).
AIW Jllrl. llfltll. . ~ 8·f:AT f,f,7
a. aA ,12 Program to Find ,~ Hlg hN
t In • ler tff of Nu mb «•
• Wr tt. a p,o g,_ ,. to ftnd 1M htg
he.. In I _, ... of 10 numf••
Mf• .,_ _. from 21»f,.... 2" t
■ftet the Nr lR al 2AH. • . _.
Q' Alfo,tthm
• lnltJall11e kO wflh WI-I (~ e, pointer),
• lnil lall -e R 7 wld1 OAH (count of J(Jd
a 0AJI).
• lni1lalbe location 2AH wid1 o (u• um
c 0 to be the highcll '° f,u).
• Pu1 con•~ou of 2AH Into /\.
• Clear carry na-1.
• Su b A and the number in I.he Aeriet
pointed by RO.
• If (C P• 1) d1eo cop y this new higher
number Jnto Joeatlon 2A H
• P.•bc •kip
• Inc rem ent RO.
• De cre me nt R7 and loop back to pul
ling (2AH) in.to A
• Wb cn loop end s local.ion 2AH baa
the highest number.
q- Prog,ram
MOV R0 ,#2 0H ;R0 +-2 0H
MOY. R7 , #OAH ; R7 ~0 AH
MO V 2A ff, #OOH ; [lAH] .-OOH, assumed highest 10
B..::k: MO V far
A. 2A li ; A g.cts highest number ao tar
CL R C ;C P+ -0
SU BB A,@ R0
: Compare done using subtraction
; A (bigheat 10 far )- @RO (cu.ncnt
JN C num ber )
Sk.ip ; If no carry (no borrow) then skip
MO Vi 2.AH,@RO
; Else copy current no. into [2AH] as
Skip: IN C RO new highest no.
; Poi nr, to nex t location
DJ NZ R7, Back ; Loo p till R7 becomes 0
SJM.P He re ; End the progrcU1L
Ji! ~ ere:-- (MU-Sem.& 8-E&TC) 2-eo 80S1 Ptoptll1np
• Wrb I pr:ogram to IOl't • MrlH of 10 numbera atored from location 20H onward• In ascending
order.
ar Program
MOV R7,#09H ; Outer loop count
Back2 : MOV R6, #09H ; Inner loop count
MOV R0,#20H ; Pointer to the series
Backl: MOV A, @RO ; Take 111 number in A
MOV Rl,A ; Copy the 1st number to R1
nd
INC RO ; Point RO to 2 number
CLR C ; Clear any previous carry (borrow)
SUBB A,@R0 ; Perform 1st number- 2nd number
; If 1" number is smaller, they are in correct order so skip
JC Skip . .
JZSkip ; If answer is 0, both numbers are same so skip
MOV A,Rl ; Exchange begins ... Take 1" number from RI into A
nd
XCH A.@R0 ; 1• no. goes in 2m location and 2 no. comes into A