Declaration at an ABSOLUTE address

Language reference ›› Variables ››
Parent Previous Next

Another construction may be used to force declaration at a specific address or to assign an alias to another variable or variable bit: the variable type may be followed by:

absolute-declaration = identifier-declaration ( absolute-declaration-address | absolute-declaration-fixed ) ";" .
absolute-declaration-address = ( ABSOLUTE | "@" | AT ) ( address-expression | variable ) [ offset-expression ] .
absolute-declaration-fixed = ABSOLUTE ";" .

For PMP the symbol @ or the keyword "AT" are synonyms of the ABSOLUTE keyword for variables declaration (@ is only used to get a pointer to a variable in standard Pascal).

As an option, it is possible to add an offset expression after the aliased variable.


<absolute-declaration-fixed>:

A special syntax that indicates to the compiler that the variable as to be allocated immediately according the current configuration of the area to be used, without waiting for late optimization which decides to allocate or not the variable regarding its usage. This is useful to allocate a block of absolute variable where each item occupies always the same memory location.


CONST
 Offset = 2;    // Offset into TheVar

VAR
 IoBit1: BOOLEAN @ PORTA.0;    // bit of I/O on port A bit 0
 CarryBit: BOOLEAN @ STATUS.C; // alias to status carry
 TheVar: ARRAY[0..5] OF byte;  // buffer
 TheVarLo: BYTE @ TheVar + (Offset + 0); // alias into TheVar
 TheVarHi: BYTE @ TheVar + (Offset + 1); // alias into TheVar

{$VARIABLES $500 TO $505}
 TheVarFixed1: WORD ABSOLUTE; // Reserve memory immediately @ $500..$501 regardless of usage
 TheVarFixed2: WORD ABSOLUTE; // Reserve memory immediately @ $502..$503 regardless of usage
 TheVarFixed3: WORD ABSOLUTE; // Reserve memory immediately @ $504..$505 regardless of usage
{$VARIABLES ALL}