0% found this document useful (0 votes)
18 views9 pages

ED 3 - Compressed

Uploaded by

swapnikte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views9 pages

ED 3 - Compressed

Uploaded by

swapnikte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

-

~tfllltera & lcattona MU-Som, e"e.aTO ~ 48

~ 2-U Program to Divide two l•blt Numbere


• Wtll.e • ptOlram to dlvlde71H bv 11H,
Store Mutt lnRO (quotten1) and A1 ('9fflalndw) of link s.

•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.

~ 2.~3 Program to Add Two 8-blt Numbere (Internal RAM)

_. 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

'a. 2.4..s Pro gra m for Blo ck Tra n•f •r


·~----- ---. .,. -
(Int RAM to
• a
.,..... For ao n eo cOJJ!I • Wock o1 _,_
• • ,. • • • ..
• - • -....-. • .. • • ~- ....,. •.,.. • •
Int RAM)
~----·~~----~-~
.., • •..- • -
... • • • •

: UNv. o. \Yt,·e. -. AsuMWg I • ~ • ,,.,


I • • • •

.•
»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

MO V Rl, f30 H ;RI 4-3 0H

NO V R7,tOAH iR7 4-0 AH

MOV A.,e RO ;A4 -(R O)


Be t:
MO V ea 1,A ; [Rl )4- A

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

• biliatt?½ RI w·t& ~ \'9111 el - , t a.doll\


• 1,;~Rl~O.-Ull~\N•C\.."lll
• TJlt- ~ l ' ~ ~ ~ ll!A'\ ,.'-._
• Si.-« A lll "'-"~~I'~~! Rt ..
~ h."ffiDl!'.Dl RO"' r-.-- ~ .-~t ~ k,~-..
• l)ta,1_•tal"Rl . . ,._. ._~~~

~ 1..U Piog1am !of, Bladt Trwfw (1nt FWI to Ext RAIi)

~ ~ "R(l wt--C. ~'18 {~'tlltt ~

• 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

• Ini tial ise R 1=5 lH and R0 =40 H (Rl


, RO = 514 0H )
• Ini tial ise R3 =93 H ~ R2 =84 H (R3
, R2 = 938 4H )
• Ini tial ise R7 wit h CS H (co unt : 200
d =C 8H )
• Pu t sou rce add res s fro m (Rt , RO
) into DP I'R
• Us ing DP rR as a poi nte r, tak e dat
a fro m Ex t RA M into A
• lncrimcnt DP TR to poi nt to nex t sou rce addres
~ s
• ,,Put this inc rem ent ed add res s bac
k into (Rt , RO)
• Pu t des rioa rion add res s fro m (R3 ,
R2 ) into DP I'R
• Us ing DP TR as a pointer, store dat
a fro m A into Ext RAM
Inc rem ent DP TR to poi nt to nex t
destination address
• Put thi s inc rem ent ed add res s bac k
into (R3, R2)
• l)e cre mc nt R7 and rep eat till R7 bec
omes 0 .

T.. .._ ..r. wim thr


SJ Mlof000n\roller9 & Appbtlona (MU-Sem. 8-E&I9 2-M
8081 , , ,__ , . ,

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

Here: SJMPRere ; End the program.

'a. 2.4.9 Program to ADD 16-blt BCD numbera


• Write• program to add two 16-blt BCD, numbers atored at 20H and 22H.
Store '9ault at 24H (awn) and 26H (carry).

• 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

MOV R2, #OOH ;R2+-0


1'fOV A 20H :A+- (20H]
ADD A,22H ; A+- A + [22H]
DAA • A.._. Decima1 adjusted ~suit
MOV 24H,A : [24H] +- Result lower byte
MOV A, 21H ; A +- [21H] "
ADOC Al23H : A .._.A+ [23H] +CF
DAA ; A+- Decimal adjusted resuJt
MOV 25}{.A ; [24H] +- Result lower byte
I

JNC Skip ; If no carry. Jump to label "Skip"


' '- .
INC R2 ; Else Make R2 = I \

Skip: MOV 26H. R2 ; [26H] +- R2 {Store .cany)


Herc: SJMP Here ; End the program.
.
is. 2.4.1 OProgram to convert Packed BCD to Un-Packed BCD
r .

• 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

a, ZA.15 8051 Sorting program

(rJlU - OP.c 17. 10 r,farkSJ

• Wrb I pr:ogram to IOl't • MrlH of 10 numbera atored from location 20H onward• In ascending
order.

d' Algorithm : (Bubble Sort) •

• Compare two adjacent numbers


• If f tnt number is smaller than the second, lhcn skip
• H the two numbcB are equal, then skip
• Else, exchange the two numbers
• Rcpcat the above steps (N-1) times, in this case 9 times
• When loop breaks, repeat the whole program again N-1, in this case 9 times.

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

DEC RO ; RO points back to l "location


MOV @R0,A ; Store 2r.1 number from A to the l" location pointed by RO
INC . RO ; RO points to 2nd location for the next iteration
Skip: DJNZ R6, Backl ; Go back and repeat the inner loop
DJNZ R7, Back2 ; Go back, repeat the outer loop by reinitializing R6 and RO . 1

Herc: SJMP Here ; End the prognun, the series is sorted.


~t~ ~ •-natktnl MU ~•m. ft r.A TC
1-ftt

(I) Ualna dlrtd 1ddrt-11dna


lllode1

~fov 40l t #331 f


Mov 4111, N,,.,
H.crc; SJMJJ Hrro
1ddl't.M ln11 n1ode wllhoul ■ lflflp
(b) U.ln11 "'111,lrr lndlru-t
MOVA, #$.5H
MOV RO. #40H
MOV@R0,A
INCR0
MOV@R0,A
Herc: SJMP Herc
dra ,lng mode wl&h.a loop
(r:) llllna ttg l,l u lndlrtc1 ad
MOVA, #jj Ji
MOV lt0, #40H
MOV R7, #0211
Back! MOV @k0, A
INCR0
IJJNZ R7, Dack
Here: SJMP Hero

You might also like