Keil Logo

Absolute Variable Location

Variables can be located at absolute memory locations using the _at_ keyword. Usage:

type[memory_type] variable_name _at_ const_expr;


type Type of the variable.
memory_type Memory type for the variable. If this is excluded from the declaration, the default memory type is used. Refer to Memory Types for information about the default memory space.
variable_name Is the variable name.
const_expr Is an expression which must evaluate to an absolute constant value. The result of the expression is the address at which to locate the variable.

The absolute address following the _at_ keyword must conform to the physical boundaries of the memory space for the variable. For the xdata and code memory types, this expression is interpreted as an offset from the base address of the memory class.

The C251 compiler generates the OFFS relocation type for xdata and code variables. Refer to the A251 Assembler User's Guide for more information about relocation expressions. For all other memory types, the _at_ expression represents the absolute memory location in the physical 251 memory. The C251 compiler checks for invalid address specifications.

With C251 Version 2 or higher, any type of variable that is defined at module-level may be located on an absolute address. The following example demonstrates how to locate several different variable types using the _at_ keyword.


  • Variables located with _at_ can be placed outside memory classes without creating any linker warnings or linker errors. It is in the responsibility of the programmer to locate the variables to existing memory or peripheral space.
#define base 0x1000                           /* base address */
int near var0 _at_ (base + 10);
int near var1 _at_ (base + 10 + sizeof (var0));

/* locate string at address 0xFFFF80 */
const char far string[12] _at_ 0xFFFF80 = "TEST PROGRAM";

/* locate text at OFFS 0x7E00, the default gives 0xFF7E00 */
char code text[20] _at_ 0x7E00 = "Hello World\n";

struct led  {
  char  digit0;
  char  digit1;

/* display is accessed at XDATA:0x4000, the default gives 0x014000 */
struct led xdata display _at_ 0x4000;
  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.