This can be done with

register unsigned char counter asm("r3");

Typically, it should be safe to use r2 through r7 that way.

Registers r8 through r15 can be used for argument passing by the compiler in case many or long arguments are being passed to callees. If this is not the case throughout the entire application, these registers could be used for register variables as well.

Extreme care should be taken that the entire application is compiled with a consistent set of register-allocated variables, including possibly used library functions.

See C Names Used in Assembler Code for more details.

Back to FAQ Index.