Loops; Large Loops (Count Greater Than 63) - Motorola DSP56800 Manual

16-bit digital signal processor
Table of Contents

Advertisement

Software Techniques
Another use of the PUSH instruction is for temporary storage. Sometimes a temporary variable is required,
such as in swapping two registers. There are two techniques for doing this, the first using an unused
register and the second using a location on the stack. The second technique uses the PUSH instruction
macro and works whenever there are no other registers available. The two techniques are shown in the
following code:
; Swapping two registers (X0, R0) using an Available Register (N)
; 3 Icyc, 3 Instruction Words
MOVE
X0,N
MOVE
R0,X0
MOVE
N,R0
; Swapping two registers (X0, R0) using a Stack Location
; 4 Icyc, 4 Instruction Words
PUSH
X0
MOVE
R0,X0
POP
R0
The operation is faster using an unused register if one is available. Often, the N register is a good choice
for temporary storage, as in the preceding example.
8.6

Loops

The DSP56800 core contains a powerful and flexible hardware DO loop mechanism. It allows for loop
counts up to 8,192, it allows a large number of instructions (maximum of 64K) to reside within the body of
the loop, and hardware DO loops can be interrupted. In addition, loops execute correctly from both on-chip
and off-chip program memory, and it is possible to single step through the instructions in the loop using the
OnCE port for emulation.
The DSP56800 core also contains a useful hardware REP loop mechanism, which is very useful for very
simple, fast looping on a single instruction. It is very useful for simple nesting when the inner loop only
contains a single instruction. For a REP loop, the instruction to be repeated is only fetched once from
program memory, reducing activity on the buses. This is very useful when executing code from off-chip
program memory. However, REP loops are not interruptible.
8.6.1

Large Loops (Count Greater Than 63)

Currently, the DO instruction allows an immediate value up to the value 63 to be specified for the loop
count. When necessary, specifying an immediate value larger than 63 is done using one of the registers on
the DSP56800 core to specify the loop count. Since registers are a precious resource, it is desirable not to
use any important registers that may contain valid data. The following code shows a technique for
specifying loop counts greater than 63 without destroying any register values.
MOVE
#2048,LC
DO
LC,LABEL
;
(instructions)
LABEL
Since the LC register is already a dedicated register used for looping and is always loaded by the DO
instruction, no information is lost when this register is used to specify a larger loop count. Note that this
technique will also work with the LC register for nested loops, as long as the loading of the LC register
with immediate data occurs after the LC register is pushed for nested loops.
8-20
; X0 -> TEMP
; R0 -> X0
; TEMP -> R0
; X0 -> TEMP
; R0 -> X0
; TEMP -> R0
; Specify a loop count greater than 63
; using the LC register
; (LC register used to avoid destroying
; another register)
DSP56800 Family Manual

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents