Using saddr area (__saddr)


When declared with __saddr, external variables and static variables in a function are allocated to the saddr area.

[Function]

-

Initialized variables are allocated to the .sdata section.

-

Uninitialized variables are allocated to the .sbss section.

-

Address reference always returns a near pointer.

-

External variables and static variables in a function are allocated to the saddr area when they are declared with __saddr.

-

These variables are handled in the same way as other variables in a C source file.

[Effect]

-

Instructions that access the saddr area are shorter than those accessing the normal memory area and their object code also becomes smaller, leading to improved execution speed.

[Usage]

-

Declare __saddr in the module or function that defines variables.
In a function, only variables with the extern or static storage class specifier can be declared with __saddr.

__saddr variable-declaration;
extern __saddr  variable-declaration;
static __saddr  variable-declaration;
__saddr extern  variable-declaration;
__saddr static  variable-declaration;

[Restrictions]

-

If __saddr is specified for a const type variable, a compilation error will occur.

-

If __saddr is specified for a function, a compilation error will occur.

-

If __saddr is used for a purpose other than variable with static storage duration, a compilation error will occur.

-

If __saddr and __near or __far are specified together, a compilation error will occur.

__saddr __near int      ni;     //Error
__saddr __far int       fi;     //Error

-

If __saddr is used in a typedef declaration, a compilation error will occur.

typedef __saddr int     SI;     //Error

[Example]

The following shows a sample C source code.

__saddr int     hsmm0;          //.sbss
__saddr int     hsmm1=1;        //.sdata
__saddr int     *hsptr;         //hsptr is allocated to. sbss
                                //The pointed location is in a normal area.
void main(){
        hsmm0 -= hsmm1;
        hsptr = 0;
}

 

The following shows the declarations and section allocation in the assembly source code.

        .PUBLIC _hsmm0                  ;Declaration
        .PUBLIC _hsmm1                  ;Declaration
        .PUBLIC _hsptr                  ;Declaration
 
        .SECTION        .sbss,SBSS      ;Allocated to the .sbss section
        .ALIGN  2
_hsmm0:
        .DS     2
        .ALIGN  2
_hsptr:
        .DS     2
 
        .SECTION        .sdata,SDATA    ;Allocated to the .sdata section
        .ALIGN  2
_hsmm1:
        .DB2    0x0001

 

The following shows the code in the function.

        movw    ax, _hsmm0
        subw    ax, _hsmm1
        movw    _hsmm0, ax
        movw    _hsptr, #0x0000

[Remark]

-

Difference between the __saddr keyword and #pragma saddr

-

The __saddr keyword cannot be used together with the __near or __far keyword, and a compilation error will occur if used so.

-

#pragma saddr handles even a variable to which the __near or __far keyword is added as if __saddr was specified without a warning being output.