ARM VERSION 1.2 Computer Hardware User Manual


 
Writing ARM and Thumb Assembly Language
2-64 Copyright © 2000, 2001 ARM Limited. All rights reserved. ARM DUI 0068B
2.10.8 Avoiding problems with MAP and FIELD directives
Using
MAP
and
FIELD
directives can help you to produce maintainable data structures.
However, this is only true if the order the elements are placed in memory is not
important to either the programmer or the program.
You can have problems if you load or store multiple elements of a structure in a single
instruction. These problems arise in operations such as:
loading several single-byte elements into one register
using a store multiple or load multiple instruction (
STM
and
LDM
) to store or load
multiple words from or to multiple registers.
These operations require the data elements in the structure to be contiguous in memory,
and to be in a specific order. If the order of the elements is changed, or a new element
is added, the program is broken in a way that cannot be detected by the assembler.
There are several methods for avoiding problems such as this.
Example 2-27 shows a sample structure.
Example 2-27
MiscBase RN r10
MAP 0,MiscBase
MiscStart FIELD 0
Misc_a FIELD 1
Misc_b FIELD 1
Misc_c FIELD 1
Misc_d FIELD 1
MiscEndOfChars FIELD 0
MiscPadding FIELD (-:INDEX:MiscEndOfChars) :AND: 3
Misc_I FIELD 4
Misc_J FIELD 4
Misc_K FIELD 4
Misc_data FIELD 4*20
MiscEnd FIELD 0
MiscLen EQU MiscEnd-MiscStart
There is no problem in using
LDM
and
STM
instructions for accessing single data elements
that are larger than a word (for example, arrays). An example of this is the 20-word
element
Misc_data
. It could be accessed as follows:
ArrayBase RN R9
ADR ArrayBase, MiscBase
LDMIA ArrayBase, {R0-R5}