Data placement in registers (32-bit mode)
In 32-bit mode, the @ operator, alternatively the #pragma location directive, can be used for placing global and static variables in a register.
To place a variable in a register, the argument to the @ operator and the #pragma location directive should be an identifier that corresponds to an Arm core register in the range R4–R11 (R9 cannot be specified in combination with the ‑‑rwpi command line option).
A variable can be placed in a register only if it is declared as __no_init, has file scope, and its size is four bytes. A variable placed in a register does not have a memory address, so the address operator & cannot be used.
Within a module where a variable is placed in a register, the specified register will only be used for accessing that variable. The value of the variable is preserved across function calls to other modules because the registers R4–R11 are callee saved, and as such they are restored when execution returns. However, the value of a variable placed in a register is not always preserved as expected:
In an exception handler or library callback routine (such as the comparator function passed to
qsort) the value might not be preserved. The value will be preserved if the command line option‑‑lock_regsis used for locking the register in all modules of the application, including library modules.In a fast interrupt handler, the value of a variable in
R8–R11is not preserved from outside the handler, because these registers are banked.The
longjmpfunction and C++ exceptions might restore variables placed in registers to old values, unlike other variables with static storage duration which are not restored.
The linker does not prevent modules from placing different variables in the same register. Variables in different modules can be placed in the same register, and another module could use the register for other purposes.
Note
A variable placed in a register should be defined in an include file, to be included in every module that uses the variable. An unused definition in a module will cause the register to not be used in that module.