Memory Type Specifiers

The mikroC PRO for PIC supports usage of all memory areas.
Each variable may be explicitly assigned to a specific memory space by including a memory type specifier in the declaration, or implicitly assigned.

The following memory type specifiers can be used:

code

Description

The code memory type may be used for allocating constants in program memory.

Example
// puts txt in program memory 
const code char txt[] = "ENTER PARAMETER:";

data

Description

This memory specifier is used when storing variable to the Data RAM.

Example
// puts x in data ram
data unsigned char x;

rx

Description

This memory specifier allows variable to be stored in the working registers space (WREG0-WREG15).

  Note : In most of the cases, there will be enough space left for the user variables in the Rx space.
        However, since compiler uses Rx space for storing temporary variables, it might happen that user variables will be stored in the internal data SRAM, when writing complex programs.
Example
// puts y in working register space  	
char rx y;

sfr

Description

This memory specifier allows user to access special function registers. It also instructs compiler to maintain same identifier name in source and assembly.

  Note : Variables can only be allocated in sfr space by the means of absolute directive or at directive to a variable already allocated in sfr space.
Example
// Extern y in sfr space
extern char y; sfr;

// Puts y in sfr space by absolute (sfr addresses are MCU specific)
char y absolute 0x0F81; sfr;

// Puts y in sfr space by at
char y at PORTB;

ldm

Description

The ldm memory type is used for storing variables in the Linear Data Memory space of PIC16 Enhanced family devices.

To treat a certain variable whose size exceeds 80 bytes as a linear, ldm specifier needs to be used.

Example
// puts y in Linear Data Memory space
ldm char y;

  Note :

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code