dsp56800e Freescale Semiconductor, Inc, dsp56800e Datasheet - Page 205

no-image

dsp56800e

Manufacturer Part Number
dsp56800e
Description
16-bit Digital Signal Controller Core
Manufacturer
Freescale Semiconductor, Inc
Datasheet
;Initialize Registers
;First Example -- Indexing with Displacement
;Second Example -- Indexing with Offset Register N (N = 4)
;Third Example -- Calculating the New Address (similar to first example)
;Fourth Example -- Calculating the New Address (similar to second example)
In the second and fourth examples, the N register value is treated as a long-word offset. When the address
is calculated for the memory access, the R2 and R3 registers are offset by 4 long words (8 words), since the
long-word versions of MOVE and ADDA are used. The resulting address in each case is $1008. Where
word offsets are used, in the other two examples, the address is $1004.
6.5.3
Data structures and unions (such as those used in the C and C++ programming languages) typically contain
a mixture of data types. Because it is not possible to access word or long-word variables with a byte
pointer, word pointers should always be used when structure elements are accessed. Byte values in the
structure can still be accessed with the MOVE.B and MOVEU.B instructions, which use word pointers.
Consider an example structure in data memory. The structure contains byte, word, and long-word variables
and has its base address, a word pointer, stored in R3. Structure elements are accessed with offsets from
this base through using the (R3+x) and (R3+xxxx) addressing modes.
The code in Example 6-3 shows the initialization of a data structure and code used to access the elements.
Each of the four accumulators are loaded with a different structure variable.
STRUCT1
CODESTART MOVE.L
Freescale Semiconductor
Accessing Data Structures
MOVEU.W
TFRA
MOVEU.W
MOVE.L
MOVE.L
ADDA
MOVE.L
ADDA.L
MOVE.L
ORG
DCB
DCB
DCL
DC
ORG
MOVE.B
MOVEU.B
MOVE.W
MOVE.L
Example 6-2. Addressing Mode Examples for Long Memory Accesses
Example 6-3. Accessing Elements in a Data Structure
#$1000,R2
R2,R3
#4,N
X:(R2+4),A
X:(R3+N),A
N,R2
X:(R2),A
N,R3
X:(R3),A
x:$7000
$BB,$AA
$DD,$CC
$12345678
$FFFF
P:
#STRUCT1,R3
x:(R3+1),A
x:(R3+2),B
x:(R3+4),C
x:(R3+2),d
Address Generation Unit
; initialize base address
; make a copy of R2
; initialize register index value
; Accesses X:$1005:X:$1004
; Accesses X:$1009:X:$1008
; Calculated Address = $1004
; Accesses X:$1005:X:$1004
; Calculated Address = $1008
; Accesses X:$1009:X:$1008
; Data Structure named “STRUCT1”
; four chars: 1st is $AA, 2nd is $BB
; 3rd is $CC, 4th is $DD
; 1 long containing $12345678
; 1 word containing $FFFF
; (instructions located in program memory)
; set up base to data structure
; read with offset of 1 byte from R3
; read with offset of 2 bytes from R3
; read with offset of 4 words from R3
; read with offset of 2 words from R3
Word Pointer Memory Accesses
6-11

Related parts for dsp56800e