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, compact, 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) compact;

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 internal 8051 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 can select which of the three possible reentrant stacks and frame pointers to use. Stack access in the SMALL model is more efficient than in the LARGE model.

  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.