12.3 Locating a Function at a Specific Address
In this example, function func
is located at a specific
address. A built-in compiler function is used to calculate the program memory address,
which is not otherwise available in C.
#include "stdio.h"
void __attribute__((address(0x2000))) func()
{}
void main()
{
void *addr;
addr = &func;
printf("0x2000 = 0x%lx\n", addr);
}
The equivalent function definition in assembly language appears below. The
.align
directive is optional and represents the default alignment in
program memory. Use of *
as a section name causes the assembler to
generate a unique name based on the source file name.
.section *,address(0x2000),code
.global _func
.align 4
_func:
return