cancel
Showing results for 
Search instead for 
Did you mean: 

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

VAvag.1
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

6 REPLIES 6
KnarfB
Principal III

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]

AScha.3
Chief III

https://lmgtfy.app/?q=declare+an+array+in+assembly+language

If you feel a post has answered your question, please click "Accept as Solution".

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

Thank You for response!

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

Thank You for response! I like this idea!