3.22 __regvar Keyword

The IAR __regvar keyword places static storage duration variables in registers or register sets.

Suggested Replacement

There is an MPLAB XC8 feature that performs a similar tasks to this keyword, but there are some differences in its effect.

Use the asm("reg") syntax along with the standard register keyword when defining an object to place that object in a register or in consecutive registers. Note that the compiler will issue an error if an attempt is made to reserve critical registers (like argument registers or the frame pointer register) using this option.

Caveats

The compiler might use the registers assign in different translation units.

Examples

Consider migrating IAR code such as:
__regvar __no_init int myVar @ 14;
 
volatile int x;
int main() {
    x = myVar;
}
and the --lock_regs 2IAR compiler option to MPLAB XC8 code similar to:
register int myVar asm("r14");
 
volatile int x;
int main() {
    x = myVar;
}

Further Information

See the Register Usage and Variables in Registers section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on writing interrupt functions.