Register Bank Access

The C51 compiler allows you to define the default register bank in a function.  The REGISTERBANK control directive allows you to specify the default register bank to use for all functions in a source file. This directive, however, does not generate code to switch the register bank.

Upon reset, the 8051 loads the PSW with 00h which selects register bank 0. By default, all non-interrupt functions use register bank 0. To change this, you must:

    Modify the startup code to select a different register bank

    Specify the REGISTERBANK control directive along with the new register bank number.

By default, the C51 compiler generates code that accesses the registers R0-R7 using absolute addresses. This is done for maximum performance. Absolute register accesses are controlled by the AREGS and NOAREGS control directives. Functions which employ absolute register accesses must not be called from another function that uses a different register bank. Doing so causes unpredictable results because the called function assumes a different register bank is selected. To make a function insensitive to the current register bank, the function must be compiled using the NOAREGS control directive. This would be useful for a function that was called from the main program and also from an interrupt function that uses a different register bank.

NOTE
The C51 compiler does not and cannot detect a register bank mismatch between functions. Therefore, make sure that functions using alternate register banks call only other functions that do not assume a default register bank.

Refer to the chapter entitled “Compiling with C51” for more information regarding the REGISTERBANK, AREGS, and NOARGES directives.