I have some simple static array defined in c-file (const int data_input[1024];)and I need to access it from my assembly code. What’s the right way to do it?
So far, I’ve been doing it this way:
.global data_input
data_input_ptr:
.word data_input
my_function:
adr r1, data_input_ptr
bx lr
AFAIK, adr is pseudo-op stands to ldr r1, =data_input_ptr or something like that.
To me the way I do it seems not to be very correct: first of all that adr r1, data_input might potentially use pc relative addressing directly if it detected at link time that it’s possible.
Another issue is about PIC: what if the code has to be position independent. How then does it work if value of data_input_ptr has to be initialized by the loader (am I correct about that?)
The way you are doing it should work, but another way of handling it would be to use the address of the array as a second argument to the assembly function. Something like this: