Sun May 12, 2013 12:10 am
for i = n1 to n2
#include <p18F8720.inc>
radix dec
n equ D'50'
sum_hi set 0x01 ; high byte of sum
sum_lo set 0x00 ; low byte of sum
i set 0x02 ; loop index i
org 0x00 ; reset vector
goto start
org 0x08
retfie
org 0x18
retfie
start clrf sum_hi,A ; initialize sum to 0
clrf sum_lo,A ;
clrf i,A ; initialize i to 0
incf i,F,A ; i starts from 1
sum_lp movlw n ; place n in WREG
cpfsgt i,A ; compare i with n and skip if i > n
bra add_lp ; perform addition when i less or equal 50
bra exit_sum ; it is done when i > 50
add_lp movf i,W,A ; place i in WREG
addwf sum_lo,F,A ; add i to sum_lo
movlw 0
addwfc sum_hi,F,A ; add carry to sum_hi
incf i,F,A ; increment loop index i by 1
bra sum_lp
exit_sum nop
bra exit_sum
end
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.