12.2 Locating a Variable at a Specific Address
In this example, array buf1
is located at a specific
address in data memory. The address of buf1
can be confirmed by executing
the program in the simulator, or by examining the link map.
#include "stdio.h"
int __attribute__((address(0x900))) buf1[128];
void main()
{
printf("0x900 = 0x%x\n", &buf1);
}
The equivalent array definition in assembly language appears below. The
.align
directive is optional and represents the default alignment in
data memory. Use of *
as a section name causes the assembler to generate a
unique name based on the source file name.
.section *,address(0x900),bss,near
.global _buf1
.align 2
_buf1: .space 256