selection sort in arm
AREA RESET, DATA, READONLY
EXPORT __Vectors
__Vectors
DCD 0X10001000
DCD Reset_Handler
ALIGN
AREA MYCODE, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
LDR R0, =LIST
LDR R1, =RESULT
MOV R10, #10
loader
LDR R2, [R0], #4
STR R2, [R1], #4
SUB R10, #1
CMP R10, #0
BNE loader
LDR R1, =RESULT
MOV R9, #10
MOV R10, R9
MOV R2, R1
MOV R0, R1
LDR R3, [R0]
find_min_each_iteration
LDR R4, [R2], #4
CMP R3, R4
BLO here
; It means R4 < R3 which means minimum value is at location R2-4
; Load R3 with minimum value and the R5 with the location of the minimum value
MOV R5, R2
MOV R3, R4
here
SUB R10, #1
CMP R10, #0
BNE find_min_each_iteration
; Swap the numbers at the location R0, R5
LDR R6, [R0]
STR R6, [R5, #-4]
STR R3, [R0], #4
MOV R2, R0
LDR R3, [R0]
SUB R9, #1
MOV R10, R9
CMP R9, #0
BNE find_min_each_iteration
LIST DCD 0x10, 0x05, 0x33, 0x24, 0x56, 0x77, 0x21, 0x04, 0x87, 0x01
AREA DATABASE, DATA, READWRITE
RESULT DCD 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
END