Datasheet

ARM Compiler Reference
ARM DUI 0067D Copyright © 1999-2001 ARM Limited. All rights reserved. 3-11
number (for example, r4). In C, global register variables cannot be
qualified or initialized at declaration. In C++, any initialization is treated
as a dynamic initialization. Valid types are:
any integer type, except
long long
any pointer type.
For example, to declare a global integer register variable allocated to r5
(the ATPCS register v2), use the following:
__global_reg(2) int x;
The global register must be specified in all declarations of the same
variable. For example, the following is an error:
int x;
__global_reg(1) int x; // error
Also,
__global_reg
variables in C cannot be initialized at definition. For
example, the following is an error in C, though not in C++:
__global_reg(1) int x=1; // error in C
Depending on the ATPCS variant used, between five and seven integer
registers, and four floating-point registers are available for use as global
register variables. In practice, using more than three global integer
register variables in ARM code, or one global integer register variable in
Thumb code, or more than two global floating-point register variables is
not recommended.
Note
In Thumb,
__global_reg(4)
is not allowed.
Unlike register variables declared with the standard
register
keyword,
the compiler does not move global register variables to memory as
required. If you declare too many global variables, code size increases
significantly. In some cases, your program might not compile.
Caution
You must take care when using global register variables because:
There is no check at link time to ensure that direct calls between
different compilation units are sensible. If possible, define global
register variables used in a program in each compilation unit of the
program. In general, it is best to place the definition in a global
header file. You must set up the value in the global register early in
your code, before the register is used.