dsp56800 Freescale Semiconductor, Inc, dsp56800 Datasheet - Page 207

no-image

dsp56800

Manufacturer Part Number
dsp56800
Description
16-bit Digital Signal Controllers
Manufacturer
Freescale Semiconductor, Inc
Datasheet
8.6.2
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
iterations from 1 to 2
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
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
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 DSC 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.
; Software Looping: Case 1
; Data ALU Register Used for Loop Count
LABEL:
;
Freescale Semiconductor
TSTW
BLE
DO
ASL
MOVE
(instructions)
DECW
BGT
Variable Count Loops
Software Loops
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.
X0
LABEL
X0,LABEL
A
#3,X0
X0
LABEL
k
times (where k is the number of bits in the LC register, or 13). It is important to
; Load loop count to execute the loop three times
; Enters loop at least once
; Back to top-of-loop if positive and not 0
13
times. For the case where the number of iterations is negative, the
; Skip over loop if loop count <= 0
Software Techniques
NOTE:
Loops
8-21

Related parts for dsp56800