Memory Type Specifiers

The mikroPascal 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:

code

Description

Program memory (64 KBytes); accessed by opcode MOVC @A+DPTR.

The code memory type may be used for constants and functions. This memory is accessed using 16-bit addresses and may be on-chip or external.

Example
// puts txt in program memory 
const txt : string[11] = 'Enter text:'; 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
var x : byte; 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  	
var x : byte; 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 the bdata type refer to the Migration Issues.
Example
// puts x in bdata	
var x : byte; 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	
var x : byte; 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 pdata is limited in size (to 256 bytes).

Example
// puts x in pdata	
var x : byte; pdata;

rx

Description

This memory specifier allows variable to be stored in the Rx space, R0-R7 (Register file).

  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, when writing complex programs it might happen that user variables will be stored in the on-chip RAM.
  • This memory specifier is used by compiler only and user should not utilize it.
Example
// puts R0 in Rx space	
R0 : byte; absolute 0x00; 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.

  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
var y : char; sfr; external;

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

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

  Note :

Copyright (c) 2002-2013 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