Mov A,#30h Mov r0,#40h Mov r1,#42 Loop: Mov @r0, A Inc r0 DJNZ r1, Loop .End

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 80

Program 1: Write a program to copy the value 30H to RAM memory locations 40H to

69H using indirect loop.


Solution :

.org 0000h
mov a,#30h
mov r0,#40h
mov r1,#42
loop: mov @r0,a
inc r0
djnz r1,loop
.end
LST

000001 0000 .org 0000h


000002 0000 7430 mov a,#30h
000002 0002 7840 mov r0,#40h
000004 0004 792A mov r1,#42
000005 0006 F6 loop: mov @r0,a
000006 0008 08 inc r0
000007 0009 D9FC djnz r1,loop
000008 000A .end
Program 2: Write a program to clear 20 RAM locations starting from 80H
Solution :

.org 0000h
clr a
mov r0,#80h
mov r1,#20
loop: mov @r0,a
inc r0
djnz r1,loop
.end
LST

000001 0000 .org 0000h


000002 0000 E4 clr a
000003 0001 7880 mov r0,#80h
000004 0003 758180 mov sp,#80h
000005 0006 7914 mov r1,#20
000006 0008 F6 loop: mov @r0,a
000007 0009 08 inc r0
000008 000A 0581 inc sp
000009 000C D9FA djnz r1,loop
000010 000E .end
Program 3: Write a program to copy 10 bytes of data from RAM locations starting
from 35H to RAM locations starting at 60H.
Solution :

.org 0000h
mov r0,#35h
mov r1,#60h
mov r2,#10
loop:mov a,@r0
mov @r1,a
inc r1
inc r0
djnz r2,loop
.end
LST

000001 0000 .org 0000h


000002 0000 7835 mov r0,#35h
000003 0002 7960 mov r1,#60h
000004 0004 7A0A mov r2,#10
000005 0006 E6 loop:mov a,@r0
000006 0007 F7 mov @r1,a
000007 0008 09 inc r1
000008 0009 08 inc r0
000009 000A DAFA djnz r2,loop
000010 000C .end
Program 4: Assume the register A has packed BCD 29H , write a program to
convert packed BCD to ASCII numbers and place them in R2 and R6.
Solution :

.org 0000h
mov a,#29h
mov r2,a
anl a,#0fh
orl a,#30h
mov r6,a
mov a,r2
anl a,#0f0h
swap a
orl a,#30h
mov r2,a
.end
LST

000001 0000 .org 0000h


000002 0000 7429 mov a,#29h
000003 0002 FA mov r2,a
000004 0003 540F anl a,#0fh
000005 0005 4430 orl a,#30h
000006 0007 FE mov r6,a
000007 0008 EA mov a,r2
000008 0009 54F0 anl a,#0f0h
000009 000B C4 swap a
000010 000C 4430 orl a,#30h
000011 000E FA mov r2,a
000012 000F .end
Program 5: Write a program to find number of 1s in a given byte.
Solution :

.org 0000h
mov r1,#00h
mov r7,# 8
mov a,#96h
again: rlc a
jnc next
inc r1
next: djnz r7, again
.end
LST

000001 0000 .org 0000h


000002 0000 7900 mov r1,#00h
000003 0002 7F08 mov r7,# 8
000004 0004 7496 mov a,#96h
000005 0006 33 again: rlc a
000006 0007 5001 jnc next
000007 0009 09 inc r1
000008 000A DFFA next: djnz r7, again
000009 000C .end
Program 6: Assume that RAM locations 40H to 44Hcontain the daily temp. of five
days. Search to see if any of these values equate to 96. If the value 96 exists in any of
these values shift it to R4 otherwise clear.
Solution :

.org 0000h
mov r0,#40h
mov r1,#5h
mov r4,#00
loop: mov a,@r0
cjne a,#96 ,ahead
mov r4,a
ahead: inc r0
djnz r1,loop
.end
LST

000001 0000 .org 0000h


000002 0000 7840 mov r0,#40h
000003 0002 7905 mov r1,#5h
000004 0004 7C00 mov r4,#00
000005 0006 E6 loop: mov a,@r0
000006 0007 B46001 cjne a,#96 ,ahead
000007 000A FC mov r4,a
000008 000B 08 ahead: inc r0
000009 000C D9F8 djnz r1,loop
000010 000E .end
Program 7: Write a program to convert the given Hex number into decimal
numbers.
Solution :

.org 0000h
mov r0,#15h
mov a,r0
mov b,#10
div ab
mov r3,b
mov b,#10
div ab
mov r4,b
mov r5,a
.end
LST

000001 0000 .org 0000h


000002 0000 7815 mov r0,#15h
000003 0002 E8 mov a,r0
000004 0003 75F00A mov b,#10
000005 0006 84 div ab
000006 0007 ABF0 mov r3,b
000007 0009 75F00A mov b,#10
000008 000C 84 div ab
000009 000D ACF0 mov r4,b
000010 000F FD mov r5,a
000011 0010 .end
Program 8: Write a program to add any two 16 bit numbers.
Solution :

.org 0000h
mov a,#0c0h
add a,#0feh
mov r4,a
mov a,#3bh
addc a,#05h
mov r5,a
.end
LST

000001 0000 .org 0000h


000002 0000 74C0 mov a,#0c0h
000003 0002 24FE add a,#0feh
000004 0004 FC mov r4,a
000005 0005 743B mov a,#3bh
000006 0007 3405 addc a,#05h
000007 0009 FD mov r5,a
000008 000A .end
Program 9: Write a program to add any two 32 bit numbers.
Solution

.org 0000h
mov a,#0c0h
add a,#0feh
mov r4,a
mov a,#3bh
addc a,#05h
mov r5,a
mov a,#45h
addc a,#0c7h
mov r6,a
mov a,#01h
addc a,#56h
mov r7,a
.end
LST

000001 0000 .org 0000h


000002 0000 74C0 mov a,#0c0h
000003 0002 24FE add a,#0feh
000004 0004 FC mov r4,a
000005 0005 743B mov a,#3bh
000006 0007 3405 addc a,#05h
000007 0009 FD mov r5,a
000008 000A 7445 mov a,#45h
000009 000C 34C7 addc a,#0c7h
000010 000E FE mov r6,a
000011 000F 7401 mov a,#01h
000012 0011 3456 addc a,#56h
000013 0013 FF mov r7,a
000014 0014 .end
Program 10: Push the contents of B register to TMOD register.
Solution :

.org 0000h
mov b,#08h
mov 89h,b
mov tmod,b
.end
LST

000001 0000 .org 0000h


000002 0000 75F008 mov b,#08h
000003 0003 85F089 mov 89h,b
000004 0006 85F089 mov tmod,b
000005 0009 .end
Program 11: Copy the program byte 0100H to 0102H to internal RAM locations
20H to 22H.
Solution :

.org 0000h
mov dptr, #0100h
mov r0,#20h
mov r1,#03h
movx a,@dptr
loop: mov a,@r0
inc r0
inc dptr
djnz r1,loop
.end
LST

000001 0000 .org 0000h


000002 0000 900100 mov dptr, #0100h
000003 0003 7820 mov r0,#20h
000004 0005 7903 mov r1,#03h
000005 0007 E0 movx a,@dptr
000006 0008 E6 loop: mov a,@r0
000007 0009 08 inc r0
000008 000A A3 inc dptr
000009 000B D9FB djnz r1,loop
000010 000D .end
Program 12: Swap bytes in timer 0.
Solution :

.org 0000h
mov r1,8ah
mov r0,8ch
mov 8ah,@r0
mov 8c,@ r1
.end
LST

000001 0000 .org 0000h


000002 0000 A98A mov r1,8ah
000003 0002 A88C mov r0,8ch
000004 0004 868A mov 8ah,@r0
000005 0006 8708 mov 8c,@ r1
000006 0008 .end
Program 13: Copy the data in internal RAM locations 12H to 15H to external RAM
locations 0200H to 0203H.
Solution :

.org 0000h
mov dptr,#0200h
mov r0,#04h
mov r1,#12h
loop: mov a,@r1
movx @dptr,a
inc r1
inc dptr
djnz r0,loop
.end
LST

000001 0000 .org 0000h


000002 0000 900200 mov dptr,#0200h
000003 0003 7804 mov r0,#04h
000004 0005 7912 mov r1,#12h
000005 0007 E7 loop: mov a,@r1
000006 0008 F0 movx @dptr,a
000007 0009 09 inc r1
000008 000A A3 inc dptr
000009 000B D8FA djnz r0,loop
000010 000D .end
Program 14a: Treat registers R1 and R2 as 16 bit registers and rotate them one
place to left.
Solution :

.org 0000h
mov r2,#80h
mov r1,#86h
mov r4,#00
mov a,r2
rlc a
jnc ahead
mov r4,#01h
ahead: mov r2,a
mov a,r1
rlc a
mov r1,a
mov a,r2
add a,r4
mov r2,a
.end .
LST

000001 0000 .org 0000h


000002 0000 7A80 mov r2,#80h
000003 0002 7986 mov r1,#86h
000004 0004 7C00 mov r4,#00
000005 0006 EA mov a,r2
000006 0007 33 rlc a
000007 0008 5002 jnc ahead
000008 000A 7C01 mov r4,#01h
000009 000C FA ahead: mov r2,a
000010 000D E9 mov a,r1
000011 000E 33 rlc a
000012 000F F9 mov r1,a
000013 0010 EA mov a,r2
000014 0011 2C add a,r4
000015 0012 FA mov r2,a
000016 0013 .end
Program 14 b: Treat registers R1 and R2 as 16 bit registers and rotate them one
place to right
Solution :

.org 0000h
mov r2,#81h
mov r1,#87h
mov r4,#00
mov a,r2
rrc a
jnc ahead
mov r4,#80h
ahead: mov r2,a
mov a,r1
rrc a
mov r1,a
mov a,r2
add a,r4
mov r2,a
.end .
LST

000001 0000 .org 0000h


000002 0000 7A81 mov r2,#81h
000003 0002 7987 mov r1,#87h
000004 0004 7C00 mov r4,#00
000005 0006 EA mov a,r2
000006 0007 13 rrc a
000007 0008 5002 jnc ahead
000008 000A 7C80 mov r4,#80h
000009 000C FA ahead: mov r2,a
000010 000D E9 mov a,r1
000011 000E 13 rrc a
000012 000F F9 mov r1,a
000013 0010 EA mov a,r2
000014 0011 2C add a,r4
000015 0012 FA mov r2,a
000016 0013 .end
Program 15a: Store the least significant nibble of A into both nibbles of R5
Solution :

.org 0000h
mov a,#36h
mov r0,a
anl a,#0fh
mov r1,a
swap a
add a,r1
mov r1,a
.end
LST

000001 0000 .org 0000h


000002 0000 7436 mov a,#36h
000003 0002 F8 mov r0,a
000004 0003 540F anl a,#0fh
000005 0005 F9 mov r1,a
000006 0006 C4 swap a
000007 0007 29 add a,r1
000008 0008 F9 mov r1,a
000009 0009 .end
Program 15b: Store the most significant nibble of A into both nibbles of R5
Solution :

.org 0000h
mov a,#36h
mov r0,a
anl a,#0f0h
mov r1,a
swap a
add a,r1
mov r1,a
.end
LST

000001 0000 .org 0000h


000002 0000 7436 mov a,#36h
000003 0002 F8 mov r0,a
000004 0003 54F0 anl a,#0f0h
000005 0005 F9 mov r1,a
000006 0006 C4 swap a
000007 0007 29 add a,r1
000008 0008 F9 mov r1,a
000009 0009 .end
Program 16: EX-OR a number with whatever is contained I A so that the result
should be FF H.
Solution :

.org 0000h
mov a,#06h
mov r0,a
cpl a
xrl a,r0
mov r2,a
.end
LST

000001 0000 .org 0000h


000002 0000 7406 mov a,#06h
000003 0002 F8 mov r0,a
000004 0003 F4 cpl a
000005 0004 68 xrl a,r0
000006 0005 FA mov r2,a
000007 0006 .end
Program 17: Swap the nibbles of R0 and R1 so that the low nibble of R0 is swapped
with high nibble of R1 and low nibble of R1 is swapped with high nibble of R0.
Solution :

.org 0000h
mov r0,#76h
mov r1,#45h
mov a,r0
anl a,#0fh
swap a
mov r2,a
mov a,r0
anl a, #0f0h
swap a
add a,r2
mov r2,a
mov a,r1
anl a,#0fh
swap a
mov r3,a
mov a,r1
anl a,#0f0h
swap a
add a,r3
mov r0,a
mov a,r2
mov r1,a
.end
LST

000001 0000 .org 0000h


000002 0000 7876 mov r0,#76h
000003 0002 7945 mov r1,#45h
000004 0004 E8 mov a,r0
000005 0005 540F anl a,#0fh
000006 0007 C4 swap a
000007 0008 FA mov r2,a
000008 0009 E8 mov a,r0
000009 000A 54F0 anl a, #0f0h
000010 000C C4 swap a
000011 000D 2A add a,r2
000012 000E FA mov r2,a
000013 000F E9 mov a,r1
000014 0010 540F anl a,#0fh
000015 0012 C4 swap a
000016 0013 FB mov r3,a
000017 0014 E9 mov a,r1
000018 0015 54F0 anl a,#0f0h
000019 0017 C4 swap a
000020 0018 2B add a,r3
000021 0019 F8 mov r0,a
000022 001A EA mov a,r2
000023 001B F9 mov r1,a
000024 001C .end
Program 18: Write a program to show the masking operation.
Solution :

.org 0000h
mov a,#55h
anl a,#0fh
mov r0,a
.end
LST

000001 0000 .org 0000h


000002 0000 7455 mov a,#55h
000003 0002 540F anl a,#0fh
000004 0004 F8 mov r0,a
000005 0005 .end
PROGRAM 19: Write a program to check if a character string of length 7 stored in
RAM locations 50H onwards is a palindrome or not. If it is, output ‘Y’ to P1.

Solution:
.org 0000h
mov r0, #2
mov r1, #50h
mov a, @r1
cjne a, 56h, loop
inc r1
mov a, @r1
cjne a, 55h, loop
inc r1
mov a, @r1
cjne a, 54h, loop
mov p1, #'y'
loop: .end
LST FILE

000001 0000 .org 0000h


000002 0000 7802 mov r0, #2
000003 0002 7950 mov r1, #50h
000004 0004 E7 mov a, @r1
000005 0005 B5560D cjne a, 56h, loop
000006 0008 09 inc r1
000007 0009 E7 mov a, @r1
000008 000A B55508 cjne a, 55h, loop
000009 000D 09 inc r1
000010 000E E7 mov a, @r1
000011 000F B55403 cjne a, 54h, loop
000012 0012 759079 mov p1, #'y'
000013 0015 loop: .end
PROGRAM 20: Given a block of 100H- 200H, find out how many bytes from this block
are greater than contents of R2 and less than contents in R3. Store the count of such bytes
in R4.

Solution:

.org 0000h
mov dptr, #0100h
mov r7, #100
mov r4, #00h
mov 20h, r2
mov 21h, r3
nxt: movx a, @dptr
cjne a, 21h, lower
sjmp out
lower: jnc out
cjne a, 20h, limit
sjmp out
limit: jc out
inc r4
out: inc dptr
djnz r7, nxt
.end
LST FILE

000001 0000 .org 0000h


000002 0000 900100 mov dptr, #0100h
000003 0003 7F64 mov r7, #100
000004 0005 7C00 mov r4, #00h
000005 0007 8A20 mov 20h, r2
000006 0009 8B21 mov 21h, r3
000007 000B E0 nxt: movx a, @dptr
000008 000C B52102 cjne a, 21h, lower
000009 000F 800A sjmp out
000010 0011 5008 lower: jnc out
000011 0013 B52002 cjne a, 20h, limit
000012 0016 8003 sjmp out
000013 0018 4001 limit: jc out
000014 001A 0C inc r4
000015 001B A3 out: inc dptr
000016 001C DFED djnz r7, nxt
000017 001E .end
PROGRAM 21: Find out how many equal bytes are there between two memory blocks
10H- 20H and 20H- 30H.

Solution:

.org 0000h
mov r7, #10
mov r0, #10h
mov r1, #20h
mov r6, #00h
nxt: mov a, @r0
mov b, a
mov a, @r1
cjne a, b, nomatch
inc r6
nomatch: inc r0
inc r1
djnz r7, nxt
.end
LST FILE

000001 0000 .org 0000h


000002 0000 7F0A mov r7, #10
000003 0002 7810 mov r0, #10h
000004 0004 7920 mov r1, #20h
000005 0006 7E00 mov r6, #00h
000006 0008 E6 nxt: mov a, @r0
000007 0009 F5F0 mov b, a
000008 000B E7 mov a, @r1
000009 000C B5F001 cjne a, b, nomatch
000010 000F 0E inc r6
000011 0010 08 nomatch: inc r0
000012 0011 09 inc r1
000013 0012 DFF4 djnz r7, nxt
000014 0014 .end
PROGRAM 22: Swap bit 0 with bit 1, bit 2 with bit 3, and so on until bit 6 is swapped
with bit 7 of register R3.

Solution:

.org 0000h
mov a, r3
rl a
anl a, #0aah
push acc
mov a, r3
rr a
anl a, #55h
mov r3, a
pop acc
orl a, r3
mov r3, a
.end
LST FILE

000001 0000 .org 0000h


000002 0000 EB mov a, r3
000003 0001 23 rl a
000004 0002 54AA anl a, #0aah
000005 0004 C0E0 push acc
000006 0006 EB mov a, r3
000007 0007 03 rr a
000008 0008 5455 anl a, #55h
000009 000A FB mov r3, a
000010 000B D0E0 pop acc
000011 000D 4B orl a, r3
000012 000E FB mov r3, a
000013 000F .end
PROGRAM 23: Square any number in A, from 0 to 5, and put the result in A.
A lookup table is made use of here and the PC is set to 0001H.

Solution:

.org 0000h
movc a, @a+pc
.db 00
.db 01
.db 04
.db 09
.db 16
.db 25
.end
LST FILE

000001 0000 .org 0000h


000002 0000 83 movc a, @a+pc
000003 0001 00 .db 00
000004 0002 01 .db 01
000005 0003 04 .db 04
000006 0004 00 .db 09
000007 0005 10 .db 16
000008 0006 19 .db 25
000009 0007 .end
PROGRAM 24: A switch is connected to P1.0 and an LED to P2.7. Write a program to
get the status of the switch and send it to LED.

Solution:

.org 0000h
setb p2.7
again: mov c, p1.0
mov p2.7, c
sjmp again
.end
LST FILE

000001 0000 .org 0000h


000002 0000 D2A7 setb p2.7
000003 0002 A290 again: mov c, p1.0
000004 0004 92A7 mov p2.7, c
000005 0006 80FA sjmp again
000006 0008 .end
PROGRAM 25: A switch is connected to P1.7. write a program to check the status of
status word sw. if sw=0, send letter ‘n’ to P2, else send letter ‘y’ to it.

Solution:
.org 0000h
setb p1.7
again: jb p1.7, over
mov p2, #'n'
sjmp again
over: mov p2, #'y'
sjmp again
.end
LST FILE

000001 0000 .org 0000h


000002 0000 D297 setb p1.7
000003 0002 209705 again: jb p1.7, over
000004 0005 75A06E mov p2, #'n'
000005 0008 80F8 sjmp again
000006 000A 75A079 over: mov p2, #'y'
000007 000D 80F3 sjmp again
000008 000F .end
PROGRAM 26: Write a program to toggle bits of P1 continuously.

Solution:

.org 0000h
mov a, #55h
back: mov p1, a
cpl a
sjmp back
.end
LST FILE

000001 0000 .org 0000h


000002 0000 7455 mov a, #55h
000003 0002 F590 back: mov p1, a
000004 0004 F4 cpl a
000005 0005 80FB sjmp back
000006 0007 .end
PROGRAM 27: Write a program to find the square of a number.

Solution:

.org 0000h
clr c
mov a, #00
mov r1, r0
loop: addc a, r0
djnz r1, loop
.end
LST FILE

000001 0000 .org 0000h


000002 0000 C3 clr c
000003 0001 7400 mov a,#00
000004 0003 A900 mov r1,r0
000005 0005 38 loop: addc a,r0
000006 0006 D9FD djnz r1,loop
000007 0008 .end
PROGRAM 28: Write a program to reverse the contents of block of 10 bytes and then
transfer them from source to destination.

Solution:

.org 0000h
mov r2, #10
mov r0, #20h
mov r1, #50h
loop: mov a, @r0
mov @r1, a
inc r0
dec r1
djnz r2, loop
.end
LST FILE

000001 0000 .org 0000h


000002 0000 7A0A mov r2, #10
000003 0002 7814 mov r0, #20h
000004 0004 7932 mov r1, #50h
000005 0006 E6 loop: mov a, @r0
000006 0007 F7 mov @r1, a
000007 0008 08 inc r0
000008 0009 19 dec r1
000009 000A DAFA djnz r2, loop
000010 000C .end
PROGRAM 29: Write a program to convert a binary number to a grey number.

Solution:

.org 0000h
mov a, r0
rr a
anl a, #01
xrl a, r0
mov r1, a
.end
LST FILE

000001 0000 .org 0000h


000002 0000 E8 mov a, r0
000003 0001 03 rr a
000004 0002 5401 anl a, #01
000005 0004 68 xrl a, r0
000006 0005 F9 mov r1, a
000007 0006 .end
PROGRAM 30: Write a program to find the number of 1’s and 0’s in a byte.

Solution:

.org 0000h
mov r1, #8
mov r2, #08h
mov r0, #00h
back: rrc a
jnc next
inc ro
next: djnz r1, back
sub r2, r0
.end
LST FILE

000001 0000 .org 0000h


000002 0000 7908 mov r1, #8
000003 0002 7A00 mov r2, #08h
000004 0004 7800 mov r0, #00h
000005 0006 13 back: rrc a
000006 0007 5002 jnc next
000007 0009 0500 inc ro
000008 000B D9F9 next: djnz r1, back
000009 000D 000000 sub r2, r0
000010 0010 .end
PROGRAM 31: Write a program to find the largest number in an array.

Solution:

.org 0000h
mov r2, #10
mov r0, #50h
mov r1, #70h
mov a, @r0
again: inc r0
mov b, @r0
cjne a, b, loop
loop: jnc next
mov a, b
next: djnz r2, again
mov @r1, a
.end
LST FILE

000001 0000 .org 0000h


000002 0000 7A0A mov r2, #10
000003 0002 7832 mov r0, #50h
000004 0004 7946 mov r1, #70h
000005 0006 E6 mov a, @r0
000006 0007 08 again: inc r0
000007 0008 86F0 mov b, @r0
000008 000A B5F000 cjne a, b, loop
000009 000D 5002 loop: jnc next
000010 000F E5F0 mov a, b
000011 0011 DAF4 next: djnz r2, again
000012 0013 F7 mov @r1, a
000013 0014 .end
PROGRAM 32: Write a program to find the smallest number in an array.

Solution:

.org 0000h
mov r2, #10
mov r0, #50h
mov r1, #70h
mov a, @r0
again: inc r0
mov b, @r0
cjne a, b, loop
loop: jc next
mov a, b
next: djnz r2, again
mov @r1, a
.end
LST FILE

000001 0000 .org 0000h


000002 0000 7A0A mov r2, #10
000003 0002 7832 mov r0, #50h
000004 0004 7946 mov r1, #70h
000005 0006 E6 mov a, @r0
000006 0007 08 again: inc r0
000007 0008 86F0 mov b, @r0
000008 000A B5F000 cjne a, b, loop
000009 000D 4002 loop: jc next
000010 000F E5F0 mov a, b
000011 0011 DAF4 next: djnz r2, again
000012 0013 F7 mov @r1, a
000013 0014 .end
PROGRAM 33: Write a program to find the average of a block of n bytes.

Solution:

.org 0000h
clr c
clr a
mov r2, #20h
mov b, r0
mov a, @r2
loop: inc r2
addc a, @r2
djnz r0, loop
div ab
.end
LST FILE

000001 0000 .org 0000h


000002 0000 C3 clr c
000003 0001 E4 clr a
000004 0002 7A14 mov r2, #20h
000005 0004 88F0 mov b, r0
000006 0006 E6 mov a, @r2
000007 0007 0A loop: inc r2
000008 0008 36 addc a, @r2
000009 0009 D8FC djnz r0, loop
000010 000B 00 div ab
000011 000C .end
PROGRAM 34: Write a program to rotate register bank 0 upwards.

Solution:

.org 0000h
push 00h
push 01h
push 02h
push 03h
push 04h
push 05h
push 06h
push 07h
pop 00h
pop 07h
pop 06h
pop 05h
pop 04h
pop 03h
pop 02h
pop 01h
.end
LST FILE

000001 0000 .org 0000h


000002 0000 C000 push 00h
000003 0002 C001 push 01h
000004 0004 C002 push 02h
000005 0006 C003 push 03h
000006 0008 C004 push 04h
000007 000A C005 push 05h
000008 000C C006 push 06h
000009 000E C007 push 07h
000010 0010 D000 pop 00h
000011 0012 D007 pop 07h
000012 0014 D006 pop 06h
000013 0016 D005 pop 05h
000014 0018 D004 pop 04h
000015 001A D003 pop 03h
000016 001C D002 pop 02h
000017 001E D001 pop 01h
000018 0020 .end
PROGRAM 35: Write a program to swap bits 0, 1 with bits 2, 3 and bits 4, 5 with bits 6,
7 of R5.

Solution:

.org 0000h
mov a, r5
anl a, #03h
rl a
rl a
mov r0, a
mov a, r5
anl a, #0ch
rr a
rr a
mov r1, a
mov a, r5
anl a, #30h
rl a
rl a
mov r2, a
mov a, r5
anl a, #0c0h
rr a
rr a
add a, r2
add a, r1
add a, r0
.end
LST FILE

000001 0000 .org 0000h


000002 0000 ED mov a, r5
000003 0001 5403 anl a, #03h
000004 0003 23 rl a
000005 0004 23 rl a
000006 0005 F8 mov r0, a
000007 0006 ED mov a, r5
000008 0007 5400 anl a, #0ch
000009 0009 03 rr a
000010 000A 03 rr a
000011 000B F9 mov r1, a
000012 000C ED mov a, r5
000013 000D 541E anl a, #30h
000014 000F 23 rl a
000015 0010 23 rl a
000016 0011 FA mov r2, a
000017 0012 ED mov a, r5
000018 0013 5400 anl a, #0c0h
000019 0015 03 rr a
000020 0016 03 rr a
000021 0017 2A add a, r2
000022 0018 29 add a, r1
000023 0019 28 add a, r0
000024 001A .end
PROGRAM 36: Write a program to complement lower nibble of R5.

Solution:

.org 0000h
mov a, r5
cpl a
anl a, #0fh
mov r2, a
mov a, r5
anl a, #0f0h
add a, r2
mov r5, a
.end
LST FILE

000001 0000 .org 0000h


000002 0000 ED mov a, r5
000003 0001 F4 cpl a
000004 0002 5400 anl a, #0fh
000005 0004 FA mov r2, a
000006 0005 ED mov a, r5
000007 0006 5400 anl a, #0f0h
000008 0008 2A add a, r2
000009 0009 FD mov r5, a
000010 000A .end
PROGRAM 37: Write a program to convert a hexadecimal number to a decimal number.

Solution:

.org 0000h
mov r0, #40h
mov a, r1
mov b, #0ah
div ab
mov @r0, b
inc r0
mov b, #0ah
div ab
mov @r0, b
inc r0
mov @r0, a
.end
LST FILE

000001 0000 .org 0000h


000002 0000 7828 mov r0, #40h
000003 0002 E9 mov a, r1
000004 0003 75F000 mov b, #0ah
000005 0006 84 div ab
000006 0007 A6F0 mov @r0, b
000007 0009 08 inc r0
000008 000A 75F000 mov b, #0ah
000009 000D 84 div ab
000010 000E A6F0 mov @r0, b
000011 0010 08 inc r0
000012 0011 F6 mov @r0, a
000013 0012 .end
PROGRAM 38: Write a program to swap the contents of register bank 3 with register
bank 0.

Solution:

.org 0000h
setb psw.3
clr psw.4
mov r7, #8
back: mov a, @r0
xchg a, @r3
mov @r0, a
inc r0
inc r3
djnz r7, back
.end
LST FILE

000001 0000 .org 0000h


000002 0000 D2D3 setb psw.3
000003 0002 C2D4 clr psw.4
000004 0004 7F08 mov r7, #8
000005 0006 E6 back: mov a, @r0
000006 0007 000000 xchg a, @r3
000007 000A F6 mov @r0, a
000008 000B 08 inc r0
000009 000C 0B inc r3
000010 000D DFF7 djnz r7, back
000011 000F .end

You might also like