Documente Academic
Documente Profesional
Documente Cultură
CODE 1: Write the 8051 assembly language program to sort the following set of marks scored by
org 0h
mov 40h, #0
mov 41h, #1
mov 42h, #2
mov 43h, #3
mov 44h, #4
mov 45h, #5
mov 46h, #6
mov 47h, #7
mov 48h, #8
mov 49h, #9
mov r2, #9
mov a, @r0
back1: inc r0
mov b, @r0
cjne a,b,target1
mov @r0,a
dec r0
mov @r0,b
inc r0
sjmp target3
end
CODE 2: Write a program with three subroutines to (a) transfer the following data from on-chip
ROM to RAM locations starting at 30H, (b) add them and save the result in 70H, and (c) find the
average of the data and store it in R7. Notice that the data is stored in a code space of on-chip
ROM.(from CAT1 paper)
org 0H
lcall romtoram
lcall addition
lcall average
romtoram:
mov r2, #9
clr a
inc dptr
inc r0
ret
addition:
mov r2, #9
mov A, #0
inc r0
mov 70H, a
ret
average:
mov a, 70H
mov b, #9
div ab
mov r7, a
ret
org 250H
mydata: DB 3,6,9,7,6,4,2,8
end
(a)
(b)
(c)
CODE 3: Assume that register A has packed BCD. Write a program to convert packed BCD to two
ASCII numbers and place them in R2 and R6. (from class notes and ppt)
MOV A, #29H
MOV R2, A
ANL A, #0FH
ORL A, #30H
MOV R6, A
MOV A, R2
ANL A, #0F0H
RR A
RR A
RR A
RR A
ORL A, #30H
MOV R2, A
CODE 4: Write 8051 assembly language program to find the total number of high bits in a data
item stored in 45H. Finally store the result in R7. (from CAT1 paper)
org 0H
clr c
mov r0, #8
mov r7, #0
mov a, 45h
back: rrc a
jnc next
inc r7
end
CODE 5: Ten hex numbers are stored in RAM locations 50H onwards. Write a program to find the
biggest number in the set. The biggest number should finally be saved in 60H.(From class notes)
CJNE A, B, LOOP
LOOP: JC LOOP1
MOV B, A
INC R0
SJMP NEXT
LOOP1: INC R0
MOV 60H, A
END
CODE 6: Write a program to transfer value 41H serially (one bit at a time) via pin P2.1. Put two
highs at the start and end of the data. Send the byte LSB first.
MOV A, #41H
SETB P2.1
SETB P2.1
MOV R5, #8
HERE: RRC A
MOV P2.1,C
SETB P2.1
SETB P2.1