ARM Technical Support Knowledge Articles

MIXING MEMORY MODELS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

Article last edited on: 2005-07-15 12:53:36

Rate this article

[Bad]
|
|
[Good]
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