Friday 5 January 2018

8051 PROGRAM TO FIND THE LARGEST ELEMENT IN AN ARRAY(WITH ALGORITHM)

AIM : To find the largest element in an array

ALGORITHM :

step 1   : start
step 2   : load DPTR with address 4200
step 3   : load 50h with 00
step 4   : move the content of location pointed by DPTR to A
step 5   : move A to the reg R0
step 6   : increment DPTR
step 7   : move the content of location pointed by DPTR to A
step 8   : compare 50h to A and jump to step 14 if not equal
step 9   : increment DPTR
step 10 : decrement RO reg. and if zero flag not set then go to step 7
step 11 : move 50h to A
step 12 : move the content of A to location pointed by DPTR
step 13 : stort jump to step 13
step 14 : jump to step 9 if any carry
step 15 : move A to 50h
step 16 : stop

PROGRAM

ADDRESS   LABEL   MNEMONICS           

4100                          MOV DPTR,#4200   
4103                          MOV 50H,#00
4106                          MOVX A,@DPTR
4107                          MOV R0,A
4108                          INC DPTR
4109            L1          MOVX A,@DPTR
410A                          CJNE A,50H,4115
410D           L2           INC DPTR
410E                          DJNE R0,L1
4110                           MOV A,50H
4112                           MOVX @DPTR,A
4113            L3           SJMP L3
4115                           JC L2
4117                           MOV 50H,A
4119                           SJMP L2


OUTPUT :

4200 : 05
4201 : 09
4202 : 06
4203 : 





1 comment: