Switch to full style
PIC Assembly Articles
Post a reply

PIC Assembly For Loop Example

Sun May 12, 2013 12:10 am

PIC Assembly For Loop Example
Code:
for i = n1 to n2

to
Code:
#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
,; initialize sum to 0
clrf sum_lo
,; 
clrf i
,; initialize i to 0
incf i
,F,; i starts from 1
sum_lp movlw n 
; place n in WREG
cpfsgt i
,; 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,; place i in WREG
addwf sum_lo
,F,; add i to sum_lo
movlw 0
addwfc sum_hi
,F,; add carry to sum_hi
incf i
,F,; increment loop index i by 1
bra sum_lp
exit_sum nop
bra exit_sum
end




Post a reply
  Related Posts  to : PIC Assembly For Loop Example
 multiply two numbers in PIC assembly     -  
 macro usage PIC assembly     -  
 MULTIPLEXING Seven SEGMENT DECODER Assembly     -  
 playfair cipher assembly code     -  
 Elements of Assembly Language Instruction     -  
 TEMPERATURE AND HEAT CONTROL Assembly     -  
 Control Directives usage PIC assembly     -  
 Motor DC Speed Control by switching ON and OFF Assembly     -  
 Object File Directives Usage PIC Assembly     -  
 C++ While loop     -