Keil Logo

Memory Models

A function's arguments and local variables are stored in the default memory space specified by the memory model. Refer to Memory Models for more information.

You may, however, specify which memory model to use for a single function by including the small or large function attribute in the function declaration. For example:

#pragma small         /* Default to small model */

extern int calc (char i, int b) large reentrant;
extern int func (int i, float f) large;
extern void *tcp (char xdata *xp, int ndx) small;

int mtest (int i, int y)            /* Small model */
  return (i * y + y * i + func(-1, 4.75));

int large_func (int i, int k) large /* Large model */
  return (mtest (i, k) + 2);

The advantage of functions using the SMALL memory model is that the local data and function argument parameters are stored in the on-chip 251 RAM. Therefore, data access is very efficient. The internal memory is limited. Occasionally, the small model cannot satisfy the requirements of a very large program and other memory models must be used. For this situation, you may declare that a function use a different memory model, as shown above.

By specifying the function model attribute in the function declaration, you may select which of the two possible reentrant stacks and frame pointers to use. Stack access in the SMALL model is more efficient than in the LARGE model.


  • C251 Version 2 or higher provides the #pragma functions directive. With this directive, you can specify the model or reentrant attribute for one or more functions individually without having to modify the function declaration. For more information, refer to the FUNCTIONS directive.
  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.