'How to traverse memory for the Fibonacci sequence in ARM assembly

I must write the following function in its own assembly file: void fillFibonacciArray(int *array, int n); The function writes into the array the first n Fibonacci numbers, i.e., each element is the sum of the prior two elements.

What I have so far:

fillFibonacciArray:
        cmp r1, 0
        beq allDone

        mov r6, 1
        str r6, [r0]            @ Arr[0] = 1
        cmp r1, 1
        beq allDone

        mov r6, 1
        str r6, [r0, 4]         @ Arr[1] = 1
        cmp r1, 2
        beq allDone
        mov r4, 3               @ int i = 3


loop:
        ldr r2, [r0, -4]        @ Arr[i-2]
        add r5, r2, r0      @ Arr[i-2] + Arr[i-1]
        mov r6, r5              
        str r6, [r0, 4]         @ Arr[i] = Arr[i-2] + Arr[i-1]

        add r4, r4, 1           @ i++
        cmp r4, r1              @ i < n?? branch to loop if it is
        blt loop

        b allDone

allDone:
       bx lr 

My confusion begins with accessing the previous two values. Do I use logical shifting to move around the array or is offsetting capable of accomplish this task? Any help is appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source