Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
49
Добавлен:
27.04.2015
Размер:
4.26 Mб
Скачать

Software Techniques

 

 

PUSH

LC

; Save outer loop registers if nested loop

 

PUSH

LA

 

 

DO

#N,LABEL

 

 

(instructions in loop)

 

Bcc

EXITLP

; 2 Icyc for each iteration

;

(instructions)

; 3 Icyc if loop terminates when true

 

LABEL

BRA

OVER

; 3 additional Icyc for BRA when exiting loop

 

 

 

 

; if normal exit

EXITLP

ENDDO

 

; 1 additional Icyc for ENDDO when exiting

OVER

 

 

; loop if exit via Bcc

POP

LA

; Restore outer loop registers if nested loop

 

;

POP

LC

 

 

 

 

;

------ or with another technique ------

;

PUSH

LC

; Save outer loop registers if nested loop

 

 

PUSH

LA

 

 

DO

#N,LABEL

 

;(instructions)

Bcc

OVER

; 3 Icyc for each iteration

ENDDO

 

; 6 Icyc if loop terminates when true

BRA

LABEL

 

OVER

 

 

(instructions)

 

LABEL

 

 

POP

LA

; Restore outer loop registers if nested loop

POP

LC

 

8.7 Array Indexes

The flexible set of addressing modes on the DSP56800 architecture allow for several different ways to index into arrays. Array indexing usually involves a base address and an offset from this base. The base address is the address of the first location in the array, and the offset indicates the location of the data in the array. For example, the first value in the array typically has an offset of 0, whereas the fourth element has an offset of 3. The nth element is always accessed with an offset of n - 1.

There are two types of arrays typically implemented: global arrays (whose base address is fixed and known at assembly time) and local arrays (whose base address may vary as the program is running). Global arrays that are small in size can benefit from the single-word instruction that directly accesses the first 128 locations of the X data memory, as well as the indexed with short displacement addressing mode.

8.7.1 Global or Fixed Array with a Constant

This type of array indexing is performed with the X:#xxxx or X:<aa> addressing mode, where the assembler adds the base address to the constant offset into the array. Arrays that are small in size can be indexed using the X:<aa> addressing mode, saving one program word and one instruction cycle. It is also possible to use the X:(Rn+xxxx) or X:(R2+xx) addressing modes if the base address of the array is stored in a Rn register.

8-26

DSP56800 Family Manual

 

Array Indexes

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

8-27

Соседние файлы в папке DSP568xx