ARM Technical Support Knowledge Articles


Applies to: C51 C Compiler


Information in this article applies to:


I have a large application that was written using the Keil C51 Compiler Version 6.10. I have upgraded to Version 6.23 and now, when I compile, my program no longer works.

I need the features in 6.23 to complete my application. I also need the code packing ability of the LX51 Linker to make my code fit into the memory space.

What's the best way to locate the problems porting from 6.10 to 6.23?


Porting a working application to a new or updated compiler can be a difficult task. If you are not the original software designer or if you have a poor understanding of the application, the tools, the hardware, the microcontroller, the system architecture, or the C programming language it will be much more difficult. In most cases, assumptions were made in the original design and development that are no longer true in the newer tools — it is your job to find and correct these problems.

C51 Versions 6.20 and later add a number of new compiler optimizations that shrink program size. Version 6.23 offers linker code packing which further reduces program size. These new optimizations may break existing applications because the code generated may execute faster or slower than previous versions and because the optimizer may even remove dead code entirely. Therefore, you must carefully migrate the source code, one file at a time if necessary, to the newer tools.

Fortunately, you can migrate the application in a methodical process that will help you locate and identify program modules that have problems with the new optimizations.

For this article, we'll refer to C51 Versions prior to 6.20 as OLDER and Versions 6.20 and later as NEWER.

The idea is to create a copy of your current project that allows you to migrate your source files from the OLDER compiler to the NEWER compiler. In the KEILC51BIN folder (which contains the NEWER tools), you must have copies of the C51.EXE file from the OLDER and from the NEWER tools. You must create a project that has groups for the OLDER files and for the NEWER files. Batch files must be created that copy the OLDER and NEWER compilers to C51.EXE so that uVision can build the proper OBJ files. Initially, all source files will be added to the OLDER group (which will compile using the OLDER compiler).

To setup your tools configuration...

  1. Make sure you have the latest release of the C51 Toolset installed on your computer.
  2. In the KEILC51BIN folder, copy the NEWER C51.EXE file to C51_V623.EXE (for version 6.23).
  3. In the KEILC51BIN folder, copy the OLDER C51.EXE file to C51_V610.EXE (for version 6.10).
  4. In the KEILC51BIN folder, create the following two batch files:
    • INIT_610.BAT
      copy /b c:keilc51inc51_v610.exe c:keilc51inc51.exe
    • INIT_623.BAT
      copy /b c:keilc51inc51_v623.exe c:keilc51inc51.exe
  5. Create a new project in uVision and add a group for the OLDER compiler and a group for the NEWER compiler.
  6. Add the INIT_???.BAT files to the corresponding group. When the batch file is added, be sure you select Custom File for the file type. After adding the batch file, you must manually edit the options for the file. Right click on the batch file in the project file list and make sure Include In Target Build and Always Build are both checked. Then, copy the path to the Customer Arguments at the bottom of the Options dialog. These batch files swap out the compiler so that the OLDER and NEWER files are built using the correct compiler.
  7. Add all of your source files to the OLDER group. Be sure that the INIT batch file stays at the top of this list.
  8. After adding all the files to your project, open the Options for Target dialog, select the Output tab, and select the INIT_623.BAT file under Run User Program #1. This ensures that the NEWER compiler is replaced after each build.

Building the Project

You should now be able to build your project (using the ORDER compiler and the NEWER linker). It should work exactly as it did before. If it does not, check the listing files for each C file to be sure that the OLDER compiler build the object file. The compiler version number is listed in the page header.

If you cannot get your program to work using the OLDER compiler and the NEWER linker, you may have a problem with the order of the files in the project.

Once you can build your project with the OLDER compiler and link it with the NEWER linker, you are ready to start migrating to the NEWER compiler.

Migrating Your Source Files

  1. In uVision, drag one file (start with the simplest files) from the OLDER group into the NEWER group. Make certain the batch file remains at the beginning of the list.
  2. Build your project and test it to see if it works. Be sure to check the listing file for the file you just moved to be sure that it is being compiled by the NEWER compiler.
  3. If your application works, move another file from the OLDER group to the NEWER group and test.
  4. If your application stops working, you should compare the compiler output (the code generated) for the file you just migrated.

Comparing Compiler Output

  1. Make sure that assembler code is generated and included in your listing files. In uVision2, in Project Options, Listing Tab, select Assembly Code in the C Compiler Listing section.
  2. Move the file (that cause the application to fail) back to the OLDER group, build the project, and save the .LST file that is generated. You may want to rename it to older.filename.lst.
  3. Move the file to the NEWER group and build the project. Now, you can open the OLDER .lst file and the NEWER .lst file, select Tile Vertically from uVision2's Window menu, and compare the output of the files. There is a great shareware utility called WDIFF that generates a differences listing that may help with that.
  4. Check the differences between the files for problems that may affect your application. Basically, you are looking for things like timing loops that the compiler optimized out, things that execute in more or less instructions, and so on.

Article last edited on: 2006-02-16 17:47:05

Rate this article

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