LIST P=16F877A ; Using PIC16F877A microcontroller
#INCLUDE <P16F877A.INC> ; Include header file
ORG 00 ; Start of program memory
DATA1 EQU 40 ; Location to keep count (N)
SUM EQU 50 ; Location to store result
GOTO MAIN ; Jump to MAIN program
ORG 30 ; Code starts here
MAIN MOVLW 0x41 ; Load starting address of numbers
MOVWF FSR ; Put it in FSR (pointer to numbers)
MOVLW 00 ; Clear W (this will hold SUM = 0)
LOOP ADDWF INDF,0 ; Add number at FSR to W
INCF FSR ; Go to next number
DECFSZ DATA1,1 ; Decrease counter (N)
GOTO LOOP ; If not 0 → repeat
MOVWF SUM ; Store result in SUM location
HLT GOTO HLT ; Stop program
END