Memory Types
The C251 Compiler provides access to all 251 memory areas.
Variables may be explicitly assigned to a specific memory space (by
including a memory type specifier in the declaration) or implicitly
assigned (based on the memory model).
The following table summarizes the memory type specifiers you may
use.
Memory Type |
Description |
bdata |
Bit-addressable internal data memory (16
bytes).
Supports mixed bit and byte access. |
code |
Program memory (64 KBytes).
Accessed by opcode MOVC @A+DPTR. |
data |
Directly addressable internal data memory (128
bytes).
Provides fastest access to variables. |
ebdata |
Bit-addressable internal data memory.
Allows mixed bit and byte access.
Address range is 20H-7FH. |
idata |
Indirectly addressable internal data memory (256
bytes).
Accessed across the full internal address space. |
near |
64 KByte directly/indirectly addressable
memory.
Overlaps the data and idata spaces.
Accessed with MOV @WRj or MOV dir16 instructions.
If applied to a function, an LCALL or ACALL (16-bit call)
instruction is generated. |
far |
Provides access to the full 16 MByte address
space.
Indirectly addressed by MOV @DRk instructions.
Address calculation is performed with 16-bit operations (this
limits the size of a single object, array, or structure to 64
KBytes.
If applied to a function, an ECALL (24-bit call) instruction is
generated. |
huge |
Provides access to the full 16 MByte address
space.
Indirectly addressed by MOV @DRk instructions.
Address calculation is performed with 32-bit operations (this
supports objects of unlimited size). |
xdata |
External data memory (64 KBytes).
Accessed by MOVX @DPTR. |
As with the signed and unsigned attributes, you may
include memory type specifiers in the variable declaration. For
example:
char data var1;
char code text[] = "ENTER PARAMETER:";
unsigned long xdata array[100];
float idata x,y,z;
unsigned char xdata vector[10][4][4];
char bdata flags;
Note
-
For compatibility with previous versions of the C251 Compiler,
you may specify the memory area before the data type. For
example, the following two declarations are equivalent:
data char x; // Old-Style Memory Type Declaration
char data x; // New-Style Memory Type Declaration
Nonetheless, this feature should not be used in new programs
because it may not be supported in future versions of the C251
Compiler. Be careful when using the old C251 syntax with
memory-specific pointers. For example, the following two
declarations are equivalent:
data char *x; // Old-Style Memory Type Declaration
char *data x; // New-Style Memory Type Declaration
-
Accessing the internal data memory is considerably faster than
accessing the external data memory. For this reason, place
frequently used variables in internal data memory. Place larger,
less frequently used variables in external data memory.
If no memory type is specified for a variable, the compiler
implicitly locates the variable in the default memory space
determined by the memory model: TINY, XTINY,
SMALL, XSMALL, or LARGE. Function arguments and
automatic variables that cannot be located in registers are also
stored in the default memory area. Refer to Memory Models for more information.
Related Knowledgebase Articles