assemblyarmcpu-registersdisassemblycortex-m

How to declare and load multiple array values into RAM with ARM assembly?


I want to create an array in memory like I would in C with

int i[] = {0,2,3,124,324,23,3,2}

How to do this in ARM assembly? Apparently I could declare some values like this:

AREA     mydata, DATA
array    DCD 0,2,3,124,324,23,3,2

But how to copy them to RAM in the most easiest way?


Solution

  • When you assemble/link a file with the lines you have given, the values will already be stored in RAM. There will be a symbol called 'array' which represents a pointer to the data.

    If you wish to access the symbol from another file, you will also need to add an EXPORT directive to the file which contains the definition, eg

    EXPORT array
    

    and add an IMPORT directive to the file where you wish to use the symbol, eg

    IMPORT array
    

    You can also check the assembler syntax by looking at the assembly language output from the compiler which compiling a trivial source file containing your declaration of i.