A.6.5 Optimization of External Variable Accesses when the Base Register is Specified

When R13 is specified as the base register of the RAM section, accesses to the RAM section are performed relative to the R13 register. Furthermore, if optimization of inter-module external variable accesses is enabled, the value relative to the R13 register is optimized, and the instruction size becomes smaller if the value is 8 bits or less.

[Example]

Source code before improvement

int a;
int b;
int c;
int d;
void fu{
     a=0;
     b=1;
     c=2;
     d=3;
}

 

Assembly-language expansion code before improvement

_func:
     MOV.L #_a,R4
     MOV.L #0000000H,[R4]
     MOV.L #_b,R4
     MOV.L #00000001H,{R4}
     MOV.L #_c,R4
     MOV.L #00000002H,[R4]
     MOV.L #_d,[R4]
     MOV.L #00000003H,[R4]
     RTS

 

Source code after improvement

int a;
int b;
int c;
int d;
void fu{
     a=0;
     b=1;
     c=2;
     d=3;
}

 

Assembly-language expansion code after improvement

_func:
     MOV.L #0000000H,_a-__RAM_TOP:16[R13]
     MOV.L #0000001H,_b-__RAM_TOP:16[R13]
     MOV.L #0000002H,_c-__RAM_TOP:16[R13]
     MOV.L #0000003H,_d-__RAM_TOP:16[R13]
     RTS