The C51 standard library contains definitions for a number of macros that allow you to access explicit memory addresses. These macros are defined in ABSACC.H. Each of these macros is defined to be used like an array.
#define CBYTE ((unsigned char *) 0x50000L)
rval = CBYTE [0x0002];
to read the contents of the byte in program memory at address 0002h.
#define CWORD ((unsigned int *) 0x50000L)
rval = CWORD [0x0002];
to read the contents of the word in program memory at address 0004h (2 × sizeof (unsigned int) = 4).
NOTE
The index used with this macro does not represent the memory
address of the integer value. To obtain the memory address, you
must multiply the index by the sizeof an integer (2 bytes).
#define DBYTE ((unsigned char *) 0x40000L)
rval = DBYTE [0x0002];
DBYTE [0x0002] = 5;
to read or write the contents of the byte in internal data memory at address 0002h.
#define DWORD ((unsigned int *) 0x40000L)
rval = DWORD [0x0002];
DWORD [0x0002] = 57;
to read or write the contents of the word in internal data memory at address 0004h (2 × sizeof (unsigned int) = 4).
NOTE
The index used with this macro does not represent the memory
address of the integer value. To obtain the memory address, you
must multiply the index by the sizeof an integer (2 bytes).
#define PBYTE ((unsigned char *) 0x30000L)
rval = PBYTE [0x0002];
PBYTE [0x0002] = 38;
to read or write the contents of the byte in pdata memory at address 0002h.
#define PWORD ((unsigned int *) 0x30000L)
rval = PWORD [0x0002];
PWORD [0x0002] = 57;
to read or write the contents of the word in pdata memory at address 0004h (2 × sizeof (unsigned int) = 4).
NOTE
The index used with this macro does not represent the memory
address of the integer value. To obtain the memory address, you
must multiply the index by the sizeof an integer (2 bytes).
#define XBYTE ((unsigned char *) 0x20000L)
rval = XBYTE [0x0002];
XBYTE [0x0002] = 57;
to read or write the contents of the byte in external data memory at address 0002h.
#define XWORD ((unsigned int *) 0x20000L)
rval = XWORD [2];
XWORD [2] = 57;
to read or write the contents of the word in external data memory at address 0004h (2 × sizeof (unsigned int) = 4).
NOTE
The index used with this macro does not represent the memory
address of the integer value. To obtain the memory address, you
must multiply the index by the sizeof an integer (2 bytes).