5.9.2. Relative maps

If you need to access data from more than 4KB away, 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.

You can access data in the structure described in Example 5.15 from an instruction at any address. This program fragment shows how:

	MOV		r9,#4096						; or #0x1000
	LDR		r4,[r9,constb - 4096]

The assembler calculates (constb - 4096) for you. However, it is better to redesign the map description as in Example 5.16.

Example 5.16. 

		MAP		0
consta		#		4		; consta uses four bytes, located at offset 0
constb		#		4		; constb uses four bytes, located at offset 4
x		#		8		; x uses eight bytes, located at offset 8
y		#		8		; y uses eight bytes, located at offset 16
string		#		256		; string is up to 256 bytes long, starting at offset 24

Using the map in Example 5.16, you can access the data structure at the same location as before:

	MOV		r9,#4096
	LDR		r4,[r9,constb]

This program fragment assembles to exactly the same machine instructions as before. The value of each label is 4096 less than before, so the assembler does not need to subtract 4096 from each label to find the offset. The labels are relative to the start of the data structure, instead of being absolute. 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. You avoid typing - 4096 repeatedly by using this method. The code is also easier to follow.

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 may be located anywhere in memory.

There are restrictions on what addresses can be loaded into a register using the MOV instruction. See Loading addresses into registers for details of how to load arbitrary addresses.

Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D
Non-Confidential