ARM Technical Support Knowledge Articles

PROBLEMS WHEN LOCATING FUNCTIONS IN CODE BANKS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

Article last edited on: 2006-10-24 13:12:04

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential