fork download
  1. LIST P=16F877A ; Using PIC16F877A microcontroller
  2. #INCLUDE <P16F877A.INC> ; Include header file
  3.  
  4. ORG 00 ; Start of program memory
  5. DATA1 EQU 40 ; Location to keep count (N)
  6. SUM EQU 50 ; Location to store result
  7.  
  8. GOTO MAIN ; Jump to MAIN program
  9.  
  10. ORG 30 ; Code starts here
  11.  
  12. MAIN MOVLW 0x41 ; Load starting address of numbers
  13. MOVWF FSR ; Put it in FSR (pointer to numbers)
  14.  
  15. MOVLW 00 ; Clear W (this will hold SUM = 0)
  16.  
  17. LOOP ADDWF INDF,0 ; Add number at FSR to W
  18. INCF FSR ; Go to next number
  19. DECFSZ DATA1,1 ; Decrease counter (N)
  20. GOTO LOOP ; If not 0 → repeat
  21.  
  22. MOVWF SUM ; Store result in SUM location
  23. HLT GOTO HLT ; Stop program
  24.  
Success #stdin #stdout 0.02s 25800KB
stdin
Standard input is empty
stdout
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