Program to search an element in an array


14. Program to search an element in an array :

mov r0,#05h ;Load r0 with immediate data 05h
clr a ;clear a
mov dptr,#9000h ;load dptr with address 9000h
mov r1,#0ah ;load r1 with immediate data 0ah
l1:mov a,#0h ;load a with 00
movc a,@a+dptr ;move data from code memory location to a
mov r2,a ;move data from a to r2
inc dptr ;increment dptr
dec r1 ;decrement r1
cjne r2,#05h,l2 ;compare r2 with 05h, if not equal, jump to label l2
mov dptr,#900ah ;load dptr with immediate data 900ah
mov a,#0ffh ;laod a with immediate data 0ffh
movx @dptr,a ;move data from a to external memory location
sjmp here
l2:cjne r1,#0h,l1 ; compare r1 with 0, if not equal, jump to label l1
mov dptr,#900ah ;load dptr with 900ah
mov a,#0h ;load a with 00h
movx @dptr,a ;move data from a to external memory location
here:sjmp here
end
Input:05,
9000h: 01 02 03 04 05 06 07 08 09 0a
Output:0ff


Web Statistics