Total members 11838 |It is currently Thu Dec 03, 2020 11:46 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

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









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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