Absolute address allocation specification (#pragma address)


Declare #pragma address in the module in which the variable to be allocated in an absolute address is to be defined. Variables can be allocated to the arbitrary address.

[Function]

-

The specified variable is allocated to the specified address.

[Effect]

-

Variables can be allocated to desired addresses.

[Usage]

-

Declare #pragma address in the module in which the variable to be allocated in an absolute address is to be defined.

#pragma address [(]variable-name=absolute-addressNote[,...][)]

Note

Absolute-address : Effective address (binary, octal, decimal, or hexadecimal constant in
C language)

[Restrictions]

-

#pragma address should be specified before declaration of the target variable. #pragma address after a variable declaration has no effect (no warning is output).

-

If an object that is not a variable is specified, an error will occur.

-

If #pragma address is specified for a const-qualified variable, an error will occur. [V1.04 or earlier]

#pragma address i=0xf2000
const int       i = 0;          //Error

-

If #pragma address is specified for a variable declared with an initial value, an error will occur. [V1.04 or earlier]

-

If #pragma address is specified for a variable that is not a const-qualified variable and is declared with an initial value, an error will occur. [V1.05 or later]

#pragma address i=0xf2000
int     i = 0;                  //Error

-

If multiple #pragma address directives are specified for a single variable, an error will occur.

#pragma address i=0xf2000
#pragma address i=0xf2000       //Error
int     i;

-

If a single address is specified for separate variables or the addresses allocated to separate variables overlap, an error will occur.

-

When #pragma address is declared for a variable that is explicitly or implicitly specified as near and if the specified absolute address is not in the range from 0x0F0000 to 0x0FFFFF, a compilation error will occur. If the specified absolute address is in the SFR area, a linkage error will occur. [V1.04 or earlier]

-

When #pragma address is declared for a variable that is not a const-qualified variable and is explicitly or implicitly specified as near and if the specified absolute address is not in the range from 0x0F0000 to 0x0FFFFF, a compilation error will occur. If the specified absolute address is in the SFR area, a linkage error will occur. [V1.05 or later]

#pragma address n_i1=0xF0000
char    __near n_i1;            //Can be compiled
#pragma address n_i2=0xEFFFF
char    __near n_i2;            //Error
#pragma address n_i3=0xEFFFF
char    n_i3;                   //Error
                                //This is because bss is set to near regardless of
                                //whether -memory_model=small or medium
#pragma address f_i=0xEFFFF
char    __far f_i;              //Can be compiled

-

When the address specified for a const variable that is explicitly or implicitly specified as near is not in the mirror source area, a linkage error will occur. [V1.05 or later]

#pragma address i=0xf3000
const   int i = 0;              //Error

[Example]

The following shows a sample C source code.

#pragma address (io=0x0ffe00)
 
int     io;                     //io is allocated to address 0x0ffe00
func(void){
        io = 0;
}

 

Variables are declared and allocated to sections as follows in the assembly code.

        .PUBLIC         _io
 
        .SECTION        .bss, BSS
        .ORG            0xFFE00
_io:
        .DS             2

 

The following code is output in the function.

clrw    ax
movw    !LOWW(_io), ax

[Remark]

-

Even when #pragma address is specified, the volatile attribute is not automatically added to variables.
The -volatile option can add the volatile attribute to all static variables, including those with #pragma address.
To add the volatile attribute separately to certain variables, declare each variable with volatile appended.

-

When allocating a variable to a specified address, consider alignment of the variable. Do not allocate a variable over a 64-Kbyte boundary.