baldwindc 0 Light Poster

Hi, I am tasked with writing selection sort in assembly. We are writing for the ARM processor.

Currently, this is what I have:

sort2:
 73     stmdb    sp!, {v1-v5, lr}          @ Copy registers to stack
 74     ldrb     r5, [a2]                  @ J = n
 75     
 76     ldrb     v2, [a1]
 77     cmp      a2, #1
 78     beq      skip_sorting
 79 
 80     sub     r5, r5, #1              @ j = N-1
 81 outer_loop:
 82     cmp      r5, #0                 @ j > 0 add j-- at the bottom
 83     beq      skip_sorting
 84     
 85 inner_loop:
 86     mov     r6, r5                  @ k = j
 87     sub     r6, r6, #1              @ k = j-1
 88     cmp     r6, #-1                 @k >= 0
 89     b       outer_loop
 90     cmp
 91 
 92 
 93 
 94 skip_sorting:
 95     ldmia    sp!, {v1-v5, pc}          @ Copy stack back into registers

where I am following the prototype of:

59    for (j=N-1; j>0; j=j-1 {
 60      for (k=j-1; k >= 0; k=k-1 {
 61        if (list[k] > list[j]) {
 62          tmp = list[k];
 63          list[k]= list[j];
 64          list[j] = tmp;
 65        }
 66      }
 67    }

a1 is a pointer to the byte array of Length N
a2 the value of N

I felt pretty slick up until line 61 of the prototype c code, but then I realized I know absolutely nothing about asm and should ask for help.

if a1 is a pointer to the byte array, how do I access array[n], array[n+1]? Is my offset dependent on the platform we are running, or is this layer hidden from the programmer?

Any help is much appreciated.