Keil Logo

Absolute Variable Location

Variables may be located at absolute memory locations in your C program source modules using the _at_ keyword. The usage for this feature is:

<[>memory_type<]> type variable_name _at_ constant;


memory_type Is the memory type for the variable. If this is excluded from the declaration, the default memory space is used. Refer to Memory Models for more information about the default memory space.
type Is the variable type.
variable_name Is the variable name.
constant Is the address where the variable is located.

The absolute address following the _at_ keyword must conform to the physical boundaries of the memory space for the variable. The Cx51 Compiler checks for and reports invalid address specifications.

The following restrictions apply to absolute variable location using the _at_ keyword:

  1. Absolute variables cannot be initialized.
  2. Functions may not be located at an absolute address.
  3. Bit variables may not be located at an absolute address.

The following example demonstrates how to locate several different variable types using the _at_ keyword.

struct link
  struct link idata *next;
  char code *test;

struct link list idata _at_ 0x40;     /* list at idata 0x40 */
char xdata text[256]   _at_ 0xE000;   /* array at xdata 0xE000 */
int xdata i1           _at_ 0x8000;   /* int at xdata 0x8000 */
volatile char xdata IO _at_ 0xFFE8;   /* xdata I/O port at 0xFFE8 */
char far ftext[256]    _at_ 0x02E000; /* array at xdata 0x03E000 */

void main ( void ){ = (void *) 0;
  i1        = 0x1234;
  text [0]  = 'a';
  IO        = 6;
  ftext [0] = 'f';

If you wish to declare variables in one source module and access them in another, use the following external declarations to access the _at_ variables defined above in another source file.

struct link
  struct link idata *next;
  char        code  *test;

extern struct link idata list;    /* list at idata 0x40 */
extern char xdata text[256];      /* array at xdata 0xE000 */
extern int xdata i1;              /* int at xdata 0x8000 */
extern volatile char xdata IO;    /* xdata I/O port at 0xFFE8 */


  • To access XDATA peripherals using variables declared with the _at_ keyword, use the volatile keyword to ensure that the C compiler does not optimize out necessary memory accesses.
  • When the _at_ keyword is used to locate far variables, the most significant byte of the specified address is converted into a memory type byte to determine the location of the object.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.