Keil Logo

Register Bank Access

The Cx51 Compiler defines the default register bank in a function. The REGISTERBANK directive specifies 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.

On 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 directive along with the new register bank number

By default, the Cx51 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 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 that a different register bank is selected.

To make a function insensitive to the current register bank, the function must be compiled using the NOAREGS directive. This is useful for functions that are called from the main program and also from an interrupt function that uses a different register bank.

Note

  • The Cx51 Compiler does not and cannot detect a register bank mismatch between functions. Therefore, you must make sure that functions using alternate register banks call only other functions that do not assume a different register bank.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.