• Nie Znaleziono Wyników

Memory Access and Pointers

W dokumencie DSP56800E (Stron 67-73)

Data Types and Addressing Modes

3.5 Memory Access and Pointers

The DSP56800 core was designed to operate as a word-addressable machine, in which each address represents one 16-bit word value. The core instruction set has been enhanced to access byte, word, and long-word memory accesses while maintaining compatibility with the DSP56800 architecture. This

Data Types and Addressing Modes

There is no inherent difference between a byte address and a word address—they are both simply 24-bit quantities. Individual instructions determine how an address is used: an address in an AGU register is considered a byte pointer when it is used by instructions that expect byte pointers, and it is considered a word pointer when it is used by instructions expecting word pointers.

Instructions use the “.BP” suffix to indicate that an address register is to be used as a byte pointer. The

“.B”, “.W”, and “.L” suffixes indicate that an address register represents a word pointer. The suffix “.BP”

is also used to indicate that an absolute address is a byte address.

Characteristics of word pointers include the following:

• They indicate that an address register (R0–R5, N, SP) points to a word address in memory.

• They can be used for byte, word, or long data memory accesses.

• Immediate offsets are in bytes (for byte instructions) or in words (for word and long instructions).

Offsets in the N register are expressed in words (for word instructions) or in longs (for long instructions).

• They provide efficient accesses to structures.

• They are fully compatible with the DSP56800 architecture, which only supports word accesses.

Characteristics of byte pointers include the following:

• They indicate that an address register (R0–R5, N) points to a byte address in data memory.

• They are used for byte accesses only.

• Offsets are always in bytes.

• They can only access the lower half of the 24-bit data memory space (the lowest 223 words).

• They are extremely efficient for accessing arrays of bytes in memory.

• They cannot access program memory.

• Several instructions use address registers as byte pointers, including the following:

— MOVE.BP, MOVEU.BP

— ADD.BP, SUB.BP, CMP.BP

— INC.BP, DEC.BP, NEG.BP

— CLR.BP, TST.BP

NOTE:

The SP register cannot be used as a byte pointer. The SP register is always used as a stack pointer, so it must always be word aligned for the correct operation of instructions such as JSR, RTS, and RTI. However, it is possible to place and access bytes on the stack with the (SP – offset) addressing modes.

Byte pointers are used exclusively for accessing byte values in data memory. Word pointers, however, can be used for accessing data of any size: byte, word, or long word. The instruction itself determines if an address is used as a word or byte pointer.

A word pointer can be converted to a byte pointer by left shifting the value 1 bit, using the ASLA

instruction. Similarly, a byte pointer can be converted to a word pointer by logically right shifting the value 1 bit, using the LSRA instruction (the LSB is lost).

Memory Access and Pointers

3.5.2 Accessing Word Values Using Word Pointers

Word values are accessed from program or data memory with the MOVE.W or MOVEU.W instructions or with any of the data ALU instructions that access an operand from data memory, such as

ADD.W X:(R0),A or DEC.W X:$C200. Word memory accesses always use an address as a word pointer.

Figure 3-9 shows an example of a word access using a word pointer. The example executes the

MOVE.W A1,X:(R0) instruction. This instruction uses the value in the R0 register, $1000, as the address in X memory to which the value in A1 ($ABCD) is written.

Figure 3-9. Accessing a Word with a Word Pointer

3.5.3 Accessing Long-Word Values Using Word Pointers

Long-word values are accessed from data memory with the MOVE.L instruction or with any data ALU instruction that accesses a long-word operand from data memory, such as ADD.L X:$1000,A. Long-word memory accesses always use a word address. Each long-word value occupies two memory word locations, as shown in Figure 3-10, and is always aligned on an even word address except when SP is used. The even address holds the lower word, and the odd address holds the upper word.

Instruction: MOVE.W A1,X:(R0) Access Size: Word

$001000

X Memory

A B C D

$001000 R0

15 0

Word Address

Storage of $12345678 in Data Memory

X Memory

15 0

Word

Data Types and Addressing Modes

Although a long-word value is always located on an even word address boundary, the effective address used to access the value is not always that even word address. For all registers and addressing modes other than the stack pointer (SP), the lower even address is used when accessing a long word. In an addressing mode that uses the stack pointer, the effective address is the odd address that contains the upper word of the 32-bit value. An attempt to access a long word in any other way generates a misaligned data access exception. Refer to Section 9.3.3.2.3, “Misaligned Data Access Interrupt,” on page 9-9 for more information.

Figure 3-11 shows a long-word access using an AGU pointer register. The example executes the

MOVE.L A10,X:(R0) instruction, which uses the value in the R0 register, $1000, as a word address. The 32-bit value contained in the A accumulator, $12345678, is written to this location and the following one.

Figure 3-11. Accessing a Long Word Using an Address Register Figure 3-12 shows a long-word access using the stack pointer. The example executes the

MOVE.L A10,X:(SP) instruction, which uses the value in the SP register, $1001, as a word address. The 32-bit value contained in the A accumulator, $12345678, is written to addresses $1000 and $1001.

Instruction: MOVE.L A10,X:(R0)

Access Size: Long

Effective Address: Even Value

$001000

X Memory

5 6 7 8

$001000 R0

15 0

Word Address

1 2 3 4 Note: Even Effective Address

Instruction: MOVE.L A10,X:(SP)

$001000

X Memory

5 6 7 8

$001001 SP

15 0

Word Address

1 2 3 4 Note: Odd Effective Address

Memory Access and Pointers Note that, if the stack pointer addressing mode is used, each long value must still be aligned on an even word address boundary even though the effective address that is used to access the value is odd.

3.5.4 Accessing Byte Values Using Word Pointers

The MOVE.B and MOVEU.B instructions are useful for accessing structures or unions containing bytes as well as for accessing bytes in a stack frame. These instructions use the address registers (R0–R5, N, SP) as word pointers and use an offset value to select the upper or lower byte.

Figure 3-13 shows an example of a byte access using a word pointer. The example executes the MOVE.B A1,X:(R0+3) instruction. In this case, the address contained in R0, $1000, is added to an immediate offset after the offset has been arithmetically right shifted 1 bit to give the correct word address:

(3>>1) + $1000 = $1001. The least significant bit (LSB) of the immediate offset selects which byte at the word address is accessed. In this example, the LSB of the immediate offset (3) is set, so the upper byte of the memory word is accessed. The lowest 8 bits of the A1 register, $CD, are then written to this location.

The lower byte of the memory location $1001 is not modified.

Figure 3-13. Accessing a Byte with a Word Pointer

Instruction: MOVE.B A1,X:(R0+3)

Access Size: Byte Byte Selected: Upper

$001000 R0

$001001

X Memory

C D X X

15 0

Word Address

Word Address: $1001 Byte Select: 1 (Upper)

Byte address: $2003

LSB of Offset

$001000

Short Immediate Value “3” +

from the Instruction Word >>1

Data Types and Addressing Modes

• An absolute address (upper byte): MOVE.BP X:@hb($F000),X0

• An absolute address (lower byte): MOVE.BP X:@lb(VAR_LABEL),X0

• An absolute address (upper byte): MOVE.BP X:$108001,X0

Two of the functions in the preceding list are built into the assembler. These functions, described in Table 3-7, are useful for converting a word address or label into a byte address for instructions that expect to receive a byte address.

NOTE:

The stack pointer register is always used as a word pointer.

Figure 3-14 shows a byte access using a byte pointer. The example executes the MOVE.BP A1,X:(R0) instruction. The address contained in R0, $2001, is logically right shifted to give the correct word address,

$1000. The LSB of the R0 register selects which byte at the word address is accessed. In this example, the LSB determines that the upper byte is to be accessed at location $1000. The lowest 8 bits of the A1 register, $CD, are then written to this location. The lower byte of memory location $1000 is not modified.

Figure 3-14. Accessing a Byte with a Byte Pointer Table 3-7. Useful Built-In Assembler Functions

Assembler Function Computation

Performed Comments

@hb(value) (value<<1) + 1 Function is used to generate a byte address from a word address or label for the upper byte of a word

@lb(value) (value<<1) + 0 Function is used to generate a byte address from a word address or label for the lower byte of a word

Instruction: MOVE.BP A1,X:(R0)

Access Size: Byte Byte Selected: Upper

$002001 R0

$001000

X Memory

C D X X

15 0

Word Address

Word Address: $1000 Byte Select: 1 (Upper)

Byte address: $2001

>>1

LSB

Addressing Modes

W dokumencie DSP56800E (Stron 67-73)