C51: PROBLEMS WHEN LOCATING FUNCTIONS IN CODE BANKS
Information in this article applies to:
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?
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.
To resolve this issue, you may:
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.
Last Reviewed: Tuesday, October 24, 2006
of your data.