Keil Logo

C51: MIXING MEMORY MODELS


Information in this article applies to:

  • C51 Version 5.50

QUESTION

I have written the following code:

void foo(void)
{
  for (i=8;i>0;i--) {
    P1.2 = ~P1.2;
  }
}

In the SMALL memory model, the compiler generates assembly code that uses the DJNZ instruction. In the COMPACT and LARGE memory models, it generates codes that don't use the DJNZ instruction and appears less efficient.

It is important that this function executes as fast as possible, yet I want to use the LARGE memory model. Can I mix the SMALL and LARGE memory models somehow?

ANSWER

Yes. You can use the LARGE memory model for your project as a whole, and specify the SMALL memory model for individual functions. For example you could write the following code:

void foo(void) small
{
  for (i=8;i>0;i--) {
    P1.2 = ~P1.2;
  }
}

Be aware that if you do this for reentrant functions, then a separate reentrant stack needs to be initialized for each memory model that has reentrant functions defined. This takes up valuable data memory.

MORE INFORMATION

FORUM THREADS

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

Last Reviewed: Friday, July 15, 2005


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.