You copied the Doc URL to your clipboard.

Placing a variable at a specific address without scatter-loading

This example shows how to modify your source code to place code and data at specific addresses, and does not require a scatter file:

  1. Create the source file main.c containing the following code:

    #include <stdio.h>
    extern int sqr(int n1);
    int gSquared __attribute__((section(".ARM.__at_0x5000"))); // Place at 0x5000
    int main()
        printf("Value squared is: %d\n", gSquared);
  2. Create the source file function.c containing the following code:

    int sqr(int n1)
        return n1*n1;
  3. Compile and link the sources:

    armclang -target armv8a-arm-none-eabi -c -g function.c
    armclang -target armv8a-arm-none-eabi -c -g main.c
    armlink --force-scanlib --cpu=8-A.32 --map function.o main.o -o squared.axf

    The --map option displays the memory map of the image. Also, --autoat is the default.

In this example, __attribute__((section(".ARM.__at_0x5000"))) specifies that the global variable gSquared is to be placed at the absolute address 0x50000. gSquared is placed in the execution region ER$$.ARM.__AT_0x5000 and load region LR$$.ARM.__AT_0x5000.

The memory map shows:

  Load Region LR$$.ARM.__AT_0x5000 (Base: 0x00005000, Size: 0x00000000, Max: 0x00000004, ABSOLUTE)

    Execution Region ER$$.ARM.__AT_0x5000 (Base: 0x00005000, Size: 0x00000004, Max: 0x00000004, ABSOLUTE, UNINIT)

    Base Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x00005000   0x00000004   Data RW           7 .ARM.__AT_0x5000  main.o