Memory access methods
This section describes the memory types presented in the chapter Data storage. In addition to presenting the assembler code used for accessing data, this section will explain the reason behind the different memory types.
You should be familiar with the RX instruction set, in particular the different addressing modes used by the instructions that can access memory.
For each of the access methods described in the following sections, there are three examples:
These three examples can be illustrated by this C program:
char myVar;
char MyArr[10];
struct MyStruct
{
long mA;
char mB;
};
char Foo(int i, struct MyStruct *p)
{
return myVar + MyArr[i] + p->mB;
}The data16 memory access method
The data16 memory consists of the highest and the lowest 32 Kbytes of data memory. The code generated by the assembler to access data16 memory becomes slightly smaller. This means a smaller footprint for the application, and faster execution at runtime.
Examples
This example accesses data16 memory:
mov.l #_myVar:16,r3 ; load address of myVar
mov.l #_MyArr:16,r4 ; load address of MyArr
movu.b [r1,r4],r1 ; indexed load from MyArr
add [r3].ub,r1 ; load and add myVar
add 0x4[r2].ub,r1 ; offset p to second
; struct memberThe data24 memory access method
The highest and the lowest 8 Mbytes of data memory can be accessed using the data24 memory access method.
Examples
This example accesses data24 memory:
mov.l #_myVar:24,r3 ; load address of myVar
mov.l #_MyArr:24,r4 ; load address of MyArr
movu.b [r1,r4],r1 ; indexed load from MyArr
add [r3].ub,r1 ; load and add myVar
add 0x4[r2].ub,r1 ; offset p to second
; struct memberThe data32 memory access method
The data32 memory access method can access the entire data memory range. The data32 memory type uses 4-byte addresses, which can make the code slightly larger.
Examples
This example accesses data32 memory:
mov.l #_myVar:32,r3 ; load address of myVar
mov.l #_MyArr:32,r4 ; load address of MyArr
movu.b [r1,r4],r1 ; indexed load from MyArr
add [r3].ub,r1 ; load and add myVar
add 0x4[r2].ub,r1 ; offset p to second
; struct memberThe sbrel memory access method
The sbrel memory access method is only available when RWPI is enabled, and addressing is relative to the SB base register. The actual register that corresponds to the SB register depends on the compiler configuration. SB is allocated after the ROPI base register and after registers have been locked, and will be the highest numbered available register in the range R6–R13. This means that if RWPI is enabled but not ROPI and no registers are locked (using the --lock option), the SB register is R13, and that if both ROPI and RWPI is enabled, R12 will be used.
The sbrel memory type uses 4-byte addresses, which can make the code slightly larger.
Examples
Assuming that R12 is the RWPI base register, this example accesses sbrel memory:
add #(_MyArr - __SD_BASE):32,r12,r3 ; compute base
; address of MyArr
movu.b [r1,r3],r1 ; indexed load from MyArr
add (_myVar - __SD_BASE):16[r12].ub,r1 ; myVar can
; be accessed directly from
; sbrel
add 0x4[r2].ub,r1 ; offset p to second
; struct member