Keil Logo

C51: PROBLEMS WHEN LOCATING FUNCTIONS IN CODE BANKS


Information in this article applies to:

  • C51 Version 6.20

SYMPTOMS

I have a code banking program that I created in C51 Version 5. I am porting it to the Version 6 compiler and am having trouble.

I am locating individual functions of a C module in different code banks using the linker BANKx directives. These were described in the older 8051 Utilities User's Guide 4.95. I noticed that this is no longer described in the manuals that come with the Version 6 compiler.

The problem that I have is that function called indirectly through function pointers are not added to the bank table by the linker. Instead, the function pointer points to the actual address of the function in its code bank. If that bank is not selected when the indirect call is made, the program ends up in the middle of some other code in the wrong bank.

What causes this problem and how do I fix it?

CAUSE

The Version 6 C51 Compiler provides several new optimization levels. In Optimize Level 8 and 9 common code sequences from different functions are either combined into subroutines or copied as common entry code prior to a function. These optimizations work on the whole C module. Therefore, all functions of a module must be located in the same code bank. If you locate individual functions from the same C file in different code banks or in a code bank and the common area, the compiler may generate program that generate incorrect code bank switches. For this reason, the technique of locating individual functions in code banks is now obsolete. You may still use this feature, but it is no longer documented.

RESOLUTION

To resolve this issue, you may:

  1. Stop locating individual functions into code banks. If you have functions that MUST be located in a particular bank, place these functions in separate files.
  2. Use a lower optimizer setting (6 or less).

We are working on a new linker in which common code sequences are optimized accross a whole application (rather than module by module). This linker-based optimization (which is available in LX51/C51 Version 7) will once again allow you place functions from one module in different code banks.

MORE INFORMATION

SEE ALSO

Last Reviewed: Tuesday, October 24, 2006


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  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.