I am trying to figure out how arrays work in ARM assembly, but I am just overwhelmed. I want to initialize an array of size 20 to 0, 1, 2 and so on.
A[0] = 0
A[1] = 1
I can't even figure out how to print what I have to see if I did it correctly. This is what I have so far:
.data
.balign 4 @ Memory location divisible by 4
string: .asciz "a[%d] = %d\n"
a: .skip 80 @ allocates 20
.text
.global main
.extern printf
main:
push {ip, lr} @ return address + dummy register
ldr r1, =a @ set r1 to index point of array
mov r2, #0 @ index r2 = 0
loop:
cmp r2, #20 @ 20 elements?
beq end @ Leave loop if 20 elements
add r3, r1, r2, LSL #2 @ r3 = r1 + (r2*4)
str r2, [r3] @ r3 = r2
add r2, r2, #1 @ r2 = r2 + 1
b loop @ branch to next loop iteration
print:
push {lr} @ store return address
ldr r0, =string @ format
bl printf @ c printf
pop {pc} @ return address
ARM confuses me enough as it is, I don't know what i'm doing wrong. If anyone could help me better understand how this works that would be much appreciated.