Skip to main content
VAvag.1
Associate III
February 20, 2023
Solved

Hi All. How can I declare an array in assembler?

  • February 20, 2023
  • 3 replies
  • 6955 views

..

    This topic has been closed for replies.
    Best answer by waclawek.jan

    With asm, often the easiest way is to look at how the compiler does it, i.e. have compiler generate asm from C source (in gcc, using -C).

    Jw

    3 replies

    KnarfB
    Super User
    February 20, 2023

    ChatGPT says:

    Q: How can I declare an array in ARM Cortex-M assembler?

    A: To declare an array in ARM Cortex-M assembler, you can use the DCB (Define Byte), DCD (Define Doubleword), and DCF (Define Floating-Point) directives, depending on the type of data that you want to store in the array.

    Here are examples of how to use these directives to declare arrays of different types:

    1. Declaring an array of bytes:

    assembly

    my_array DCB 1, 2, 3, 4, 5 ; Declares an array of 5 bytes

    1. Declaring an array of 32-bit words:

    assembly

    my_array DCD 0x12345678, 0xdeadbeef, 0x87654321 ; Declares an array of 3 32-bit words

    1. Declaring an array of 64-bit doublewords:

    assembly

    my_array DCD 0x123456789abcdef0, 0xdeadbeef12345678 ; Declares an array of 2 64-bit doublewords

    1. Declaring an array of floating-point numbers:

    assembly

    my_array DCF 3.14, 2.718, 1.414 ; Declares an array of 3 single-precision floating-point numbers

    You can access individual elements of the array using the syntax:

    assembly

    my_array[index]

    VAvag.1
    VAvag.1Author
    Associate III
    February 20, 2023

    Thank You for response!

    AScha.3
    Super User
    February 20, 2023
    "If you feel a post has answered your question, please click ""Accept as Solution""."
    VAvag.1
    VAvag.1Author
    Associate III
    February 20, 2023

    Thank You for response, but the link didnt show anything.

    waclawek.jan
    waclawek.janBest answer
    Super User
    February 20, 2023

    With asm, often the easiest way is to look at how the compiler does it, i.e. have compiler generate asm from C source (in gcc, using -C).

    Jw

    VAvag.1
    VAvag.1Author
    Associate III
    February 20, 2023

    Thank You for response! I like this idea!