Keil Logo


Information in this article applies to:

  • C51 Version 7 or higher


I need to use an 8051 device variant where the MOVC instruction is broken.

MOVC A,@A+DPTR can only access constants in an certain address space (C:0xA000 - C:0xAFFF). Access to other memory regions fails. It is not possible to use the instruction MOVC A,@A+PC at all.

I know that the C51 Compiler uses MOVC instructions a lot. Is there a way to configure the Keil C51 Compiler, so that above restrictions can be achived?


When you avoid certain constructs in the C source code it is possible to minimize the MOVC instructions. In addition all constants need to be located to the specific address memory.

Configure Compiler and Linker/Locater:

The following explains the configuration settings for µVision, the C51 Compiler and the LX51 Linker/Locater that are required to avoid MOVC instructions.

  • Under Project - Options for Target - Device select the Extended Linker (LX51) instead of the BL51 Linker/Locater. The LX51 has more options to control the output.
  • Under Project - Options for Target - Target enable 'far' memory type support. This setting disables some C51 run-time library functions that use MOVC instructions which are embedded into the program code.
  • Under Project - Options for Target - LX51 Locate enter the address space for constants by using the User classes input field. Disable Use Memory Layout from Target Dialog. The User classes input may look like shown below:
    XDATA (X:0xF000-X:0xF1FF), HDATA (X:0xF000-X:0xF1FF),
    CODE (C:0x0-C:0x2FFF, C:0xA000-C:0xAFFF),
    ECODE (C:0x0-C:0x2FFF, C:0xA000-C:0xAFFF),
    CONST (C:0xa000-c:0xaFFF), HCONST (C:0xA000-c:0xAFFF)

With the settings described above all constant segments are already located to address space C:0xA000-c:0xAFFF. In addition you need to check your program code for the following issues:

Check for ?C?CCASE, ?C?ICASE, or ?C?LCASE Library Calls:

The C51 Compiler may embed DB and DW constants into the program code segment. Use the Compiler Code Listing file to check whether the code generated uses ?C?CCASE, ?C?ICASE, or ?C?LCASE library calls . If the compiler uses one of these library calls, you need to break the switch/case statements apart into several switch/case constructs (each less than 7 case statements). Refer to C51: SWITCH/CASE STATEMENTS for more information.

Do Not Use bit Initalizations at File Level:


bit b=1;

void func (void)  {

These sequences require execution of MOVC A,@A+PC instruction in INIT.A51. Instead move the bit initialization to beginning of main.

Avoid the following function calls

The C51 Run-Time Library has several routines that have DB/DW statements embedded in the libary code. Therefore, you need to avoid the following function calls in your application program.

  • The following complex floating-point functions: sin, cos, tan, asin, acos, atan, log, log10, exp, pow, sinh, cosh, tanh, ceil, fmod, floor.
  • Functions that perform ASCII conversion of floating-point numbers such as: printf, scanf, atof, strtod.
  • Pointer argument (%p) to printf.
  • Code Banking (configured in the L51_BANK.A51 module.
Generate Linker *.COD File and Check for DB/DW Statements

The following settings enable a linker code listing file (extension *.COD) that might help you to analyze the compiler output for DB and DW statements that are embedded in the code.

  • Under Project - Options for Target - Listing enable Linker Code Listing. The Linker Code Listing is useful for analysing the application for remaining MOVC instructions (see below).
  • Under Project - Options for Target - C51 enable Linker Code Packing. This allows to generate a Linker Code Listing. If your device has also broken AJMP/ACALL instructions use the NOAJMP Linker directive as explained in C51: REPLACE AJMP/ACALL WITH LJMP/LCALL

Using the above methods almost 100% ensures that the generated code is safe and does not contain any hidden DB/DW statements. In this way you can work with the broken 8051 device until you receive the final silicon version.


Last Reviewed: Tuesday, January 11, 2005

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