Variable Count Loops; Software Loops - Motorola DSP56800 Manual

16-bit digital signal processor
Table of Contents

Advertisement

This technique should not be used for the REP instruction because it will
destroy the value of the LC register if done by a REP instruction nested
within a hardware DO loop.
8.6.2

Variable Count Loops

There are cases where it is useful to loop for a variable number of times instead of a constant number of
times. For these cases the loop count is specified using a register. This allows a variable number of loop
k
iterations from 1 to 2
times (where k is the number of bits in the LC register, or 13). It is important to
consider what takes place if this variable is zero or negative. Whenever a DO loop is executed and the loop
count is zero, the loop will execute 2
number will simply be interpreted as an unsigned positive number and the loop will be entered. If there is a
possibility that a register value may be less than or equal to zero, then it is necessary to insert extra code
outside of the loop to detect this and branch over the loop. This is demonstrated in the following code.
; Hardware looping when the loop count can be negative or zero
TSTW
X0
BLE
LABEL
DO
X0,LABEL
ASL
A
LABEL
For the case of REP looping on a register value when the register contains the value 0, the instruction to be
repeated is simply skipped as desired; no extra code is required. This is also true when an immediate value
of 0 is specified. For the case where the number of iterations can be negative, the response is the same as
for the DO loop and can be solved using the preceding technique presented for DO looping.
8.6.3

Software Loops

The DSP56800 provides the capability for implementing loops in either hardware or software. For
non-nested loops in critical code sections, the hardware looping mechanism is always the fastest. However,
there is a limitation when the hardware looping mechanism is used. The DSP56800 allows a maximum of
two nested hardware DO loops. Any looping beyond this generates a HWS overflow interrupt.
Software looping techniques are also efficiently implemented on the DSP core. Software looping simply
uses a register or memory location and decrements this value until it reaches zero. A branch instruction
conditionally branches to the top of the loop.
There are three different techniques for implementing a loop in software: one using a data ALU register,
one using an AGU register, and one using a memory location to hold the loop count. Each of these is
shown in the following code.
NOTE:
13
times. For the case where the number of iterations is negative, the
; Skip over loop if loop count <= 0
Software Techniques
Loops
8-21

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents