Keil Logo

C51: Avoiding MOVC Fetches from Code Space


Information in this article applies to:

  • C51 Version 7

QUESTION

We have a special chip that is based on the Mentor 8051EW core. The memory configuration of this device allows downloading to RAM in some particular areas, but blocks the execution of the MOVC instruction in the same memory area for security reasons.

It appears that the Keil C51 Compiler embeds tables into the program code and requires the MOVC instruction (which is blocked). Is there a way to locate constant tables to a different memory area?

ANSWER

The compiler embeds constant tables into program code to improve performance of code constructs like case statements. The constants are handled using the library functions ?C?xCASE and ?C?LSTKxxxx. So, if your MAP file lists these library routines, you likely have constant tables embedded in your program's code space.

Case Statements

Case statements are implemented using several different strategies. One is to store the case information in a jump table in code space. In such a situation, the ?C?xCASE library routine handles the switch-case statement.

You can avoid this type of constant table in one of several ways:

  • Create switch/case tables that are sorted by the value of the case statements.
  • Shrink or split switch/case statements so that a maximum of 7 cases exist in each statement.
  • Use the LX51 Linker to create a special code bank for constants (see below).

?C?LSTKxxxx Function Calls

To remove calls to the ?C?LSTKxxxx function, enable Project - Options for Target - 'far' memory type support (which sets the VARBANKING compiler directive).

Project Configuration

To solve this issue, you must configure your project using a special code banking configuration. The LX51 Linker/Locater provides support for the Mentor 8051EW memory extensions. So you may configure your system with just one code bank using the L51IBANK.A51 file and the example provided in \KEIL\C51\EXAMPLES\M8051EW\L51IBANK. This code banking example allows you to define a Memory Bank for constants (so constant tables are not mixed in with program code).

MORE INFORMATION

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


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.