Keil Logo

Global Register Coloring

Global register coloring works across a complete application. When enabled, the linker generates a register definition file that contains a table of registers used by each function. The compiler uses this table to optimize register usage. Your project is re-compiled iteratively until no further register optimization is possible.

When global register coloring is enabled, compiler knows the registers used by each function. Registers that are not altered in external functions can be used to hold register variables. The code generated by the compiler requires less data and code space and executes faster.

To enable global register coloring, the REGFILE compiler directive and the REGFILE linker directive must be specified.

The following listings compare the code generated with and without global register optimization.

Global Register Coloring
Enabled
main(){
  unsigned char i;
  unsigned char a;
  while(1){
  i=input();/*get number of values*/
?C0001:
    LCALL input
;- 'i' assigned to 'R6' -
    MOV   R6,AR7

  do {
    a=input();/*get input value*/
?C0005:
    LCALL input
;- 'a' assigned to 'R7' -
    MOV   R5,AR7

    output(a);/*output value*/
    LCALL _output
    } while(--i);/*decrement values*/
    DJNZ  R6,?C0005




  }
    SJMP  ?C0001
}
    RET
CODE SIZE: 18 Bytes
Global Register Coloring
Disabled
main(){
  unsigned char i;
  unsigned char a;
  while(1){
  i=input();/*get number of values*/
?C0001:
    LCALL input
    MOV   DPTR,#i
    MOV   A,R7
    MOV   @DPTR,A
  do {
    a=input();/*get input value*/
?C0005:
    LCALL input
    MOV   DPTR,#a
    MOV   A,R7
    MOVX  @DPTR,A
    output(a);/*output value*/
    LCALL _output
    } while(--i);/*decrement values*/
    MOV   DPTR,#i
    MOVX  A,@DPTR
    DEC   A
    MOVX  @DPTR,A
    JNZ   ?C0005
  }
    SJMP  ?C0001
}
    RET
CODE SIZE: 30 Bytes
  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.