Global Or Fixed Array With A Variable; Local Array With A Constant; Local Array With A Variable; Array With An Incrementing Pointer - Motorola DSP56800 Manual

16-bit digital signal processor
Table of Contents

Advertisement

8.7.2

Global or Fixed Array with a Variable

This type of array indexing is performed with the X:(Rn+xxxx), X:(R2+xx), or X:(Rn+N) addressing
mode.
In the first two addressing modes—X:(Rn+xxxx) and X:(R2+xx)—the constant value specifies the base
address of the array, and Rn or R2 specifies the offset into the array. These first two are similar to the
method used by microcontrollers and are useful when only one or two accesses are performed with a
particular base address, because it is not necessary to load a register with the base address. The X:(R2+xx)
addressing mode executes in one fewer instruction cycle and uses one fewer instruction word than the
X:(Rn+xxxx) addressing mode. It is useful for arrays whose base address is located in the first few
locations in X data memory.
In the last addressing mode—X:(Rn+N)—Rn is the base address of the array, and N specifies the offset.
This addressing mode is best for the case where many accesses are to be performed into an array. In this
case the base address is only loaded once into the Rn register and then many accesses can be performed
using the X:(Rn+N) addressing mode. This addressing mode uses a single program word and executes in
two instruction cycles.
8.7.3

Local Array with a Constant

This type of array indexing is done with the X:(Rn+xxxx) or X:(R2+xx) addressing mode, where Rn holds
the base address of the array and the constant value specifies the constant offset into the array. (It can also
be done with the X:(SP+#xxxx) or X:(SP-#xx) addressing mode, but this is not as straightforward.) In this
case SP holds the address of the end of the stack frame, and the base address of the array is located using a
constant offset value from the stack pointer. The constant used to index into this local array is added to the
offset of the base address from the stack pointer to access the desired location of an array stored within the
stack frame. Stack frames are discussed in Section 8.8, "Parameters and Local Variables."
8.7.4

Local Array with a Variable

This type of array indexing is done with the X:(Rn+N) or X:(SP+N) addressing mode. It is similar to the
technique described in Section 8.7.3, "Local Array with a Constant," but, instead of using a constant index,
the register N holds the variable offset into the array. For the case of X:(SP+N), the N register contains the
sum of the index into the array and the offset of the array's base address from the stack pointer.
8.7.5

Array with an Incrementing Pointer

Often it is desired to sequentially access the elements in an array. This type of array indexing is most often
done with the X:(Rn)+ addressing mode, where Rn is initialized to the first element of the array of interest
and sequentially advances to each next element in the array by the automatic post-incrementing address
mode. In special cases it is also possible to use X:(Rn+N), where N holds the base address and Rn is the
incrementing array index that is advanced using an LEA (Rn)+ instruction. The latter is useful where it is
also necessary to have access to the variable that holds the index into the array, which is held in the Rn
register.
Software Techniques
Array Indexes
8-27

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents