ARM VERSION 1.2 Computer Hardware User Manual


 
Writing ARM and Thumb Assembly Language
2-52 Copyright © 2000, 2001 ARM Limited. All rights reserved. ARM DUI 0068B
2.10.1 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 on page 2-30 for details of how to
load arbitrary addresses.
Note
r9 is the static base register (sb) in the ARM-Thumb Procedure Call Standard. Refer to
the Using the Procedure Call Standard chapter in ADS Developer Guide for further
information.