Switch to full style
PIC Assembly Articles
Post a reply

find the largest element stored in the array

Mon May 13, 2013 11:58 pm

find the largest element stored in the array

Code:

arr_max equ 0x00
i equ 0x01
n equ D
'80' ; the array count
#include <p18F8720.inc>
org 0x00
goto start
org 0x08
retfie
org 0x18
retfie
start movff 0x10
,arr_max ; set arr[0] as the initial array max
lfsr FSR0
,0x11 ; place address of arr[1] in FSR0
clrf i
,; initialize loop count i to 0
again movlw n
-; number of comparisons to be made
; the next instruction implements the condition C (= n)
cpfslt i,; skip if i < n-1
bra done 
; all comparisons have been done
; the following 7 instructions update the array max
movf POSTINC0
,W

cpfsgt arr_max
,; is arr_max > arr[i]?
bra replace ; no
bra next_i 
; yes
replace movwf arr_max
,; update the array max
next_i incf i
,F,A
goto again
done nop
end




Post a reply
  Related Posts  to : find the largest element stored in the array
 find out the number of elements in an array of 8-bit element     -  
 Pop the element off the end of array     -  
 Array element navigation     -  
 access element in array C++     -  
 UnSet array element     -  
 finding the largest integer     -  
 Plug In to the Web at India's Largest Adobe Conference     -  
 Array difference for associate array     -  
 Find MAC Address     -  
 Find entity by id     -