| |||
| Home > Writing ARM and Thumb Assembly Language > Describing data structures with MAP and FIELD directives > Relative maps | |||
To access data more than 4KB away from the current instruction, you can use a register-relative instruction, such as:
LDR r4,[r9,#offset]
offset is limited to 4096, so r9 must already
contain a value within 4KB of the address of the data.
Example 2.16.
MAP 0
consta FIELD 4 ; consta uses four bytes, located at offset 0
constb FIELD 4 ; constb uses four bytes, located at offset 4
x FIELD 8 ; x uses eight bytes, located at offset 8
y FIELD 8 ; y uses eight bytes, located at offset 16
string FIELD 256 ; string is up to 256 bytes long, starting at offset 24
Using the map in Example 2.16, you can access the data structure using the following instructions:
MOV r9,#4096
LDR r4,[r9,#constb]
The labels are relative to the start of the data structure. The register used to hold the start address of the map (r9 in this case) is called the base register.
There are likely to be many LDR or STR instructions
accessing data in this data structure.
This map does not contain the location of the data structure. The location of the structure is determined by the value loaded into the base register at runtime.
The same map can be used to describe many instances of the data structure. These can be located anywhere in memory.
There are restrictions on what addresses can be loaded into
a register using the MOV instruction. Refer to Loading addresses into registers for details of
how to load arbitrary addresses.
r9 is the static base register (sb) in the ARM-Thumb Procedure Call Standard.