Keil Logo

Memory Types

The memory type of an object specifies into which memory area the object is stored. Some memory areas have fast access times but limited in the amount of space available while other memory areas are large but slow to access.

High-performance applications benefit from locating frequently-used variables in fast memory areas (like on-chip RAM). Large buffers and tables are typically located in larger memory areas (like external RAM or ROM). Refer to the HOLD directive for information on how to automatically locate variables based on size.

A number of memory types are available. Some memory types are selected by default for certain Memory Models. Other memory types are available for explicit variable declarations and are not tied to a specific memory model.

Type Description
near Supports 16-bit pointers, 16-bit address calculation, and access to:
  • up to 16 KB for variables in the NDATA group,
  • up to 16 KB for constants in the NCONST group,
  • up to 16 KB for the system area in the SDATA group.

The DPPUSE linker directive allows up to 64 KB in the NDATA and NCONST groups.

If near is applied to a function, a 16-bit call instruction (CALLA or CALLR) is generated to call the function.

bdata Bit-addressable on-chip RAM that supports mixed bit and byte accesses but is limited to 256 bytes.
idata On-chip RAM that provides the fastest access to variables.
sdata On-chip system area (address space 0C000h-0FFFFh) that may be used for Special Function Registers (SFRs) and PEC-addressable objects.
far Supports 32-bit pointers, 16-bit address calculations, and access to the entire address space. The size of a single object (array or structure) is limited to 16 KB. If far is applied to a function, a segmented call instruction (CALLS) is generated when calling the function. far is the best memory type to use on the 80C166 microcontroller for accessing the 256KB address space.
huge Supports 32-bit pointers, 16-bit address calculations, and access to the entire address space. The size of a single object (array or structure) is limited to 64 KB. huge is the best memory type on the C167/C165 microcontroller for accessing the 16MB address space.
xhuge Supports 32-bit pointers, 32-bit address calculations, and access to the entire address space. The size of a single object (array or structure) is limited to 16MB. This memory model performs more slowly than the others.

The following examples show how to use memory types in variable declarations:

char idata var1;
static unsigned long far array [100];
extern float near x, huge y;
extern unsigned int huge vector[1000][10];
unsigned char sdata pec_buffer [100];
char bdata flags; sbit flag0 = flags^0;

The following example shows how to use a memory type in a function definition:

/*************************************************/
/* function with 'NEAR' CALL and RET instruction */
/*************************************************/
void near func1 (char *p)  {
*p = 1;
}

Note

  • The near memory type may be applied to static functions in the MEDIUM or LARGE memory models to speed up calls to the function and save stack space.
  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.