|ARM Technical Support Knowledge Articles|
Applies to: C51 C Compiler
Information in this article applies to:
How can I locate a local variable in a register using C? I wish to do this in order to save on memory space.
It is not possible to locate a variable in a register using C. The register bank(s) used by the compiled code are reserved and the registers are used as needed. If your variable is local, then there is a high probability that it will be overlaid with other local variables, thus reducing data memory usage.
It is possible to write a function in assembler or write some in-line assembler to achieve this. However, you will require extra data memory to preserve the PSW, so you will not be saving any memory space. In addition, the compiled code may corrupt the register, or by changing the register you may stop compiled code from working. This is fraught with many problems and we do not recommend that you try this.
The best solution is to let the linker overlay the variable. Heavily used variables are often copied into registers for manipulation.
Article last edited on: 2004-06-09 15:20:32
Did you find this article helpful? Yes No
How can we improve this article?