I'm currently learning ARM assembly for a class and have come across a problem where I'd need to use an "array." I'm aware that there is no such thing as an array in ARM so I have to allocate space and treat that as an array. I have two questions.
loop:
but don't know how to use it to access different "indexes."So far, this is what I've gotten from reading ARM documentation as I've gathered from resources online.
.equ SWI_Exit, 0x11
.text
.global _start
_start: .global _start
.global main
b main
main:
ldr R0, =MyArray
mov R1, #42
str R1, [R0], #4
mov R1, #43
str R1, [R0], #4
swi SWI_Exit
MyArray: .skip 20 * 4
.end
As a side note, I am using ARMSim# as required by my professor, so some commands recognized by GNU tools won't be recognized by ARMSim#, or at least I believe that is the case. Please correct me if I'm wrong.
.skip
is allocating the fixed-size array.* A variable-sized, growable array would typically be implemented with more complex dyanamic memory allocation code using the stack or a heap.loop:
(the actual name is arbitrary) you could branch (back) to it by using b loop
. (Probably, you would want to do the branch conditionally so that the program didn't loop forever.) You can access different elements in the loop by changing R0
, which you are already doingAlso the b main
isn't really serving any purpose since it is branching to he next instruction. The code will do the same thing if you remove it.
[*] Alternately, you could say that your array is the just elements between MyArray
and R0
(not including the memory R0
points to), in which, by changing R0
you are extending the array. But the maximum size Is still fixed by the .skip
directive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With