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:

type ¤ memory_space ¥ variable_name at constant;
where:

type    is the type of the variable.

memory_space    is the memory space for the variable.

variable_name    is the name of the variable.

constant    is the address at which to locate the variable.

If memory_space  is missing from the declaration, the default memory space is used.

The absolute address following at must conform to the physical boundaries of the memory space for the variable. C51 checks for invalid address specifications.

The following restrictions apply to absolute variable location:

  1. Absolute variables cannot be initialized.

  2. Functions and variables of type bit cannot 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;
};

at 0x40 idata struct link list; /* list at idata 0x40 */
at 0xE000 xdata char text[256]; /* array at xdata 0xE000 */
at 0x8000 xdata int i1; /* int at xdata 0x8000 */

void main (void) {
link.next = (void *) 0;
i1 = 0x1234;
text [0] = 'a';
}