536908051 simple programs
TRANSCRIPT
-
8/13/2019 536908051 Simple Programs
1/4
Simple Programs in 8051 assembly language
Statement 1: -exchange the content of FFh and FF00h
Solution: -here one is internal memory location and other is memory externallocation. so first the content of ext memory location FF00h is loaded in acc.
then the content of int memory location FFh is saved first and then content of
acc is transferred to FFh. now saved content of FFh is loaded in acc and then it
is transferred to FF00h.
Mov dptr, #0FF00h ; take the address in dptr
Movx a, @dptr ; get the content of 0050h in a
Mov r0, 0FFh ; save the content of 50h in r0
Mov 0FFh, a ; move a to 50h
Mov a, r0 ; get content of 50h in a
Movx @dptr, a ; move it to 0050h
Statement 2: -store the higher nibble of r7 in to both nibbles of r6
Solution: first we shall get the upper nibble of r7 in r6. Then we swap nibbles
of r7 and make O operation with r6 so the upper and lower nibbles are
duplicated
Mov a, r7 ; get the content in acc
Anl a, #0F0h ; mask lower it
Mov r!, a ; send it to r!
"wap a ; xchange pper and lower niles of acc
$rl a, r! ; $% operation
Mov r!, a ; finall& load content in r!
Statement 3: - treat r6!r7 and r"!r# as two $6 bit registers. %erform
subtraction between them. &tore the result in '0h (lower byte) and '$h (higher
byte).
Solution: - first we shall clear the carry. Then subtract the lower bytes
afterward then subtract higher bytes.
'lr c ; clear carr&Mov a, r( ; get first lower &te
" a, r! ; stract it with other
Mov )0h, a ; store the reslt
Mov a, r5 ; get the first higher &te
" a, r7 ; stract from other
Mov )*h, a ; store the higher &te
-
8/13/2019 536908051 Simple Programs
2/4
Statement 4: -divide the content of r0 by r$. &tore the result in r' (answer)
and r* (reminder). Then restore the original content of r0.
Solution:-after getting answer to restore original content we have to multiply
answer with divider and then add reminder in that.Mov a, r0 ; get the content of r0 and r*
Mov , r* ; in register A and +
iv a ; divide A & +
Mov r), a ; store reslt in r)
Mov r-, ; and reminder in r-
Mov , r* ; again get content of r* in +
Ml a ; mltipl& it & answer
Add a, r- ; add reminder in new answer
Mov r0, a ; finall& restore the content of r0
Statement 5: -transfer the block of data from '0h to *0h to external location
$0'0h to $0*0h.
Solution: -here we have to transfer $0 data bytes from internal to external
+,. &o first- we need one counter. Then we need two pointers one for source
second for destination.
Mov r7, #0Ah ; initiali.e conter & *0d
Mov r0, #)0h ; get initial sorce location
Mov dptr, #*0)0h ; get initial destination location
/xt Mov a, @r0 ; get first content in acc
Movx @dptr, a ; move it to external location
1nc r0 ; increment sorce location
1nc dptr ; increase destination location
2n. r7, nxt ; decrease r73 if .ero then over otherwise move next
Statement 6: -find out how many eual bytes between two memory blocks $0h
to '0h and '0h to *0h.
Solution: -here we shall compare each byte one by one from both blocks.
/ncrease the count every time when eual bytes are foundMov r7, #0Ah ; initiali.e conter & *0d
Mov r0, #*0h ; get initial location of lock*
Mov r*, #)0h ; get initial location of lock)
Mov r!, #00h ; e4al &te conter3 "tarts from .ero
/xt Mov a, @r0 ; get content of lock * in acc
Mov , a ; move it to +
-
8/13/2019 536908051 Simple Programs
3/4
Mov a, @r* ; get content of lock ) in acc
'2ne a, , nomatch ; compare oth if e4al
1nc r! ; increment the conter
/omatch inc r0 ; otherwise go for second nmer
1nc r*d2n. r7, nxt ; decrease r73 if .ero then over otherwise move next
Statement 7: -given block of $00h to '00h. Find out how many bytes from this
block are greater then the number in r' and less then number in r*. &tore the
count in r".
Solution: -in this program- we shall take each byte one by one from given
block. ow here two limits are given higher limit in r* and lower limit in r'. &o
we check first higher limit and then lower limit if the byte is in between these
limits then count will be incremented.
Mov dptr, #0*00h ; get initial location
Mov r7, #0FFh ; conter
Mov r(, #00h ; nmer conter
Mov )0h, r) ; get the pper and lower limits in
Mov )*h, r- ; )0h and )*h
/xt Movx a, @dptr ; get the content in acc
'2ne a, )*h, lower ; check the pper limit first
"2mp ot ; if nmer is larger
ower 2nc ot ; 2mp ot
'2ne a, )0h, limit ; check lower limit
"2mp ot ; if nmer is lower
imit 2c ot ; 2mp ot
1nc r( ; if nmer within limit increment cont
$t inc dptr ; get next location
2n. r7, nxt ; repeat ntil lock completes
Statement 8:-count number of interrupts arriving on external interrupt pin
/T$. &top whencounter overflows and disable the interrupt. 1ive the
indication on pin%0.0
Solution: -as we know whenever interrpt occrs the 6' 2mps to one particlar
location where its 1"% is written3 "o we have to 2st write one 1"% that will do the 2oMovr), #00h ; initiali.e the conter
Movie, #8(h ; enale external interrpt *
9ere "2mp here ; continos loop
$rg 00*-h ; interrpt *location
1ncr) ; increment the cont
-
8/13/2019 536908051 Simple Programs
4/4