measure movlw d'3' ; This defines the number of samples taken
movwf cnt ; excluding the 'first sample'
movfw _adresh ; read the very first sample and store it
movwf sum ; in the variable 'sum'
loop movfw _adresh ; read the second sample into accu
addwf sum,f ; add both together, put answer back in sum
btfsc _status,0 ; check carry bit for overflow
incf overflow,f ; if carry bit is set, inc overflow by 1
decfsz cnt,f ; perform cnt - 1, skip next if result is 0
goto loop ; cnt != 0 so loop back for another sample
rrf overflow,f ; shift the overflow
rrf sum,f ; rrf carry (div by 2)
rrf overflow,f ; shift the overflow
rrf sum,w ; rrf carry (div by 2), copy avg to accu
return ; return without altering accu value