Memory Type Specifiers
The mikroC PRO for 8051 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 (based on a memory model).
The following memory type specifiers can be used:
Memory type specifiers can be included in svariable declaration.
For example:
char data_buffer; data; // puts data_buffer in data RAM const char txt[] = "ENTER PARAMETER:"; code; // puts text in program memory unsigned long array[100]; xdata; // puts array in external memory float ibuffer; idata; // puts ibuffer in idata RAM
If no memory type is specified for a variable, the compiler locates the variable in the memory space determined by the memory model: Small, Compact, or Large.
code
Description |
Program memory (64 KBytes); accessed by opcode MOVC @A+DPTR. The |
---|---|
Example |
// puts txt in program memory const char txt[] = "ENTER PARAMETER:"; code; |
data
Description |
Directly addressable internal data memory; fastest access to variables (128 bytes). This memory is directly accessed using 8-bit addresses and is the on-chip RAM of the 8051. It has the shortest (fastest) access time but the amount of data is limited in size (to 128 bytes or less). |
---|---|
Example |
// puts x in data ram unsigned char x; data; |
idata
Description |
Indirectly addressable internal data memory; accessed across the full internal address space (256 bytes). This memory is indirectly accessed using 8-bit addresses and is the on-chip RAM of the 8051. The amount of idata is limited in size (to 128 bytes or less) it is upper 128 addresses of RAM |
---|---|
Example |
// puts x in idata ram unsigned char x; idata; |
bdata
Description |
Bit-addressable internal data memory; supports mixed bit and byte access (16 bytes). This memory is directly accessed using 8-bit addresses and is the on-chip bit-addressable RAM of the 8051. Variables declared with the bdata type are bit-addressable and may be read and written using bit instructions. For more information about thebdata type refer to the Migration Issues.
|
---|---|
Example |
// puts x in bdata unsigned char x bdata; |
xdata
Description |
External RAM (XRAM) or Internal expanded RAM (ERAM); accessed by opcode MOVX @DPTR. See Xdata Specifics This memory is indirectly accessed using 16-bit addresses and is the external data RAM of the 8051. The amount of xdata is limited in size (to 64K or less). |
---|---|
Example |
// puts x in xdata unsigned char x; xdata; |
pdata
Description |
Paged (256 bytes) external data memory; accessed by opcode MOVX @Rn. This memory is indirectly accessed using 8-bit addresses and is one 256-byte page of external data RAM of the 8051. The amount of |
---|---|
Example |
// puts x in pdata unsigned char x; pdata; |
rx
Description |
This memory specifier allows variable to be stored in the Rx space, R0-R7 (Register file). Notes:
|
---|---|
Example |
// puts R0 in Rx space unsigned short R0; rx; |
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. ![]() |
---|---|
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; |

- If none of the memory specifiers are used when declaring a variable,
data
specifier will be set as default by the compiler.
What do you think about this topic ? Send us feedback!