4.11.3.1 Equivalent Assembly Symbols

By default AVR-GCC uses the same symbolic names of functions or objects in C and assembler code. There is no leading underscore character prepended to a C language’s symbol in assembly code.

You can specify a different name for the assembler code by using a special form of the asm() statement:

unsigned long value asm(“clock”) = 3686400;

This statement instructs the compiler to use the symbol name clock rather than value. This makes sense only for objects with static storage duration, because stack-based objects do not have symbolic names in the assembler code and these can be cached in registers.

With the compiler you can specify the use of a specific register:

void Count(void)
{
 register unsigned char counter asm("r3");
 // ... some code...
 asm volatile("clr r3");
 // ... more code...
}

The assembler instruction, clr r3, will clear the variable counter. The compiler will not completely reserve the specified register, and it might be re-used. The compiler is unable to check whether the use of the specified register conflicts with any other predefined register. It is recommended that you do not reserve too many registers in this way.

In order to change the assembly name of a function, you need a prototype declaration, because the compiler will not accept the asm() keyword in a function definition. For example:

extern long calc(void) asm ("CALCULATE");

Calling the function calc() in C code will generate assembler instructions which call the function called CALCULATE.