Download Assembler/Linker/Librarian User's Guide

Transcript
Assembler/Linker/Librarian User’s Guide
4.68.6
Application Example - while/endw
This example shows the usefulness of directive while to perform a loop while a certain
condition is true. This directive is used with the endw directive.
#include p16f877a.inc
;Include standard header file
;for the selected device.
variable i
;Define the symbol 'i' as a
;variable.
mydata udata 0x20
reg_hi res 1
reg_lo res 1
;Allocate RAM for labels
;reg_hi and reg_lo.
RST
;The code section named RST
;is placed at program memory
;location 0x0. The next two
;instructions are placed in
;code section RST.
;Jumps to the location labelled
;’start’.
CODE
pagesel
goto
start
start
shift_right
i=0
while
0x0
macro
i< by_n
by_n
;Beginning of a macro, which
;shifts register data n times.
;Code length generated after
;assembly, varies depending upon
;the value of parameter 'by_n'.
;Initialize variable i.
;Following 3 lines of assembly
;code are repeated as long as
;i< by_n.
Up to 100 lines of codes are allowed inside a while loop.
bcf
rrf
rrf
STATUS,C
reg_hi,F
reg_lo,F
i+=1
;Clear carry bit.
;reg_hi and reg_lo contains
;16-bit data which is rotated
;right through carry.
;Increment loop counter i.
i cannot increment to more than 255 decimal.
endw
;End while loop. The loop will
;break here after i=by_n.
;End of 'shift_right' macro.
endm
PGM
CODE
start
movlw
movwf
movlw
movwf
DS33014L-page 166
0x88
reg_hi
0x44
reg_lo
;This is the beginning of the
;code section named PGM. It is
;a relocatable code section
;since no absolute address is
;given along with directive CODE.
;Initialize reg_hi and
;reg_lo for observation.
 1994-2013 Microchip Technology Inc.