EasyManua.ls Logo

Microchip Technology dsPIC30F - Page 50

Microchip Technology dsPIC30F
738 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
dsPIC30F Family Reference Manual
DS70049C-page 2-32 © 2004 Microchip Technology Inc.
2.9.2 DO Loop Construct
The DO instruction can execute a group of instructions that follow it a specified number of times
without software overhead. The set of instructions up to and including the end address will be
repeated. The repeat count value for the DO instruction can be specified by a 14-bit literal or by
the contents of a W register declared within the instruction. The syntax for the two forms of the
DO instruction is given below:
DO #lit14,LOOP_END ; DCOUNT <-- lit14
Instruction1
Instruction2
:
:
LOOP_END: Instruction n
DO Wn,LOOP_END ; DCOUNT <-- Wn<13:0>
Instruction1
Instruction2
:
:
LOOP_END: Instruction n
The following features are provided in the DO loop construct:
A W register can be used to specify the loop count. This allows the loop count to be
defined at run-time.
The instruction execution order need not be sequential (i.e., there can be branches,
subroutine calls, etc.).
The loop end address does not have to be greater than the start address.
2.9.2.1 DO Loop Registers and Operation
The number of iterations executed by a DO loop will be the (14-bit literal value +1) or the (Wn
value + 1). If a W register is used to specify the number of iterations, the two MSbits of the W
register are not used to specify the loop count. The operation of a DO loop is similar to the
‘do-while’ construct in the C programming language because the instructions in the loop will
always be executed at least once.
The dsPIC30F has three registers associated with DO loops: DOSTART, DOEND and DCOUNT.
These registers are memory mapped and automatically loaded by the hardware when the DO
instruction is executed. DOSTART holds the starting address of the DO loop while DOEND holds
the end address of the DO loop. The DCOUNT register holds the number of iterations to be
executed by the loop. DOSTART and DOEND are 22-bit registers that hold the PC value. The
MSbits and LSbits of these registers is fixed to ‘0’. Refer to Figure 2-2 for further details. The
LSbit is not stored in these registers because PC<0> is always forced to ‘0’.
The DA status bit (SR<9>) indicates that a single DO loop (or nested DO loops) is active. The
DA bit is set when a DO instruction is executed and enables a PC address comparison with the
DOEND register on each subsequent instruction cycle. When PC matches the value in DOEND,
DCOUNT is decremented. If the DCOUNT register is not zero, the PC is loaded with the address
contained in the DOSTART register to start another iteration of the DO loop.
The DO loop will terminate when DCOUNT = 0. If there are no other nested DO loops in progress,
then the DA bit will also be cleared.
Note: The group of instructions in a DO loop construct is always executed at least one
time. The DO loop is always executed one time more than the value specified in the
literal or W register operand.

Table of Contents

Other manuals for Microchip Technology dsPIC30F