Technical Support

GENERAL: PROGRAM STRUCTURE FOR REGISTER OPTIMIZATION


Information in this article applies to:

  • C51 All Versions
  • C166 All Versions
  • C251 All Versions

QUESTION

I have a problem with the code efficiency of my application. In my program, I have several small interface functions, but despite the fact that I am using Global Register Optimization, the calling functions seem to assume that these interface functions are using all CPU registers. The interface functions are pretty small and use almost no CPU registers.

What is the reason for that behavior?

ANSWER

The compiler generates the functions in the same order as they appear in the C source file. It is, therefore, important that the interface functions are in the C source before they are used. Otherwise, the Compiler does not know the function code and has to assume maximum register usage.

Therefore, the program structure inside a C source module should be:

  void my_simple_func1 (void)  {
    :
  }

  void my_simple_func2 (void)  {
    :
  }

  void my_complex_func (void)  {
    :
    my_simple_func1 ();
    my_simple_func2 ();
    :
  }

For optimum register allocation, it is important that the functions which are called by other functions are coded in the C source file.

MORE INFORMATION

  • µVision Getting Started User's Guide, Global Register Optimization

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Wednesday, June 30, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure