I have to do a routine using ARM v7 that store in RAM memory 10 binary numbers and then sort these numbers from high to low using bubble sort, how should I start?
.func
bubbleSortAscendingU32:
ldr r3, [r0], #4
mov r1, #9*4
mov r12, #9*4
1:
ldr r2, [r0], #4
cmp r2, r3
strdlo r2, r3, [r0, #-8]
movhi r3, r2
subs r12, r12, #4
bgt 1b
sub r0, r0, r1
subs r1, r1, #4
ldrgt r3, [r0, #-4]
movgt r12, r1
bgt 1b
bx lr
.endfunc
Assuming we are dealing with an array of uint32_t
, that above might work.
both strdlo
and movhi
have to be replaced for other types:
Unsigned Descending:
strdhi
and movlo
Signed Ascending:
strdlt
and movgt
Signed Descending:
strdgt
and movlt
The function prototype:
void bubbleSortAscendingU32(uint32_t *pSrc);
void bubbleSortDescendingU32(uint32_t *pSrc);
void bubbleSortAscendingS32(int32_t *pSrc);
void bubbleSortDescendingS32(int32_t *pSrc);