|ARM Technical Support Knowledge Articles|
Applies to: A51 Macro Assembler
I have an 8051 program that uses code written in C and assembly. I want my assembly code to have exclusive access to several registers for global variables. These are not used in my C code, however, the code from the C compiler uses all registers (R0 to R7). Is there a way to get around this problem and how do I keep my C code from overwriting global variables stored in registers by my assembler code?
The easiest way to do this is to use a different register bank in your assembly code.
For example, by default, the C compiler uses register bank 0 for functions you create. If you select register bank 1 for your assembly routines (remember RB0 and RB1 in the PSW?) then your global register variables in your assembly modules will never get overwritten by your C code.
Make sure that your C code doesn't ever use register bank 1. Also, make sure that your assembly code specifies the RB(1) directive, so the linker "knows" that the 8-bytes from 0x08 to 0x0F are used. That way, it won't try to locate variables there.
Article last edited on: 2004-05-10 21:28:16
Did you find this article helpful? Yes No
How can we improve this article?