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, =ARRAY MOV R9, #9 LDR R9, [R9] ADD R9, R0, R9, LSL #2 ; address of one element from the end ADD R1, R0, #4 ; i pointer OUTER CMP R1, R9 ; checks append if counter BGE DONE LDR R5, [R1] MOV R2, R1 ; j pointer (inner loop) INNER SUB R2, R2, #4 ; decrements j to previous element CMP R2, R0 BLT INSERT LDR R8, [R2] CMP R8, R5 BLE INSERT STR R8, [R2, #4] ADD R1, R1, #4 B INNER INSERT STR R5, [R2, #4] ADD R1, R1, #4 B OUTER DONE B DONE AREA mydata, DATA, READWRITE ARRAY DCD 5,2,8,1,9,4,6,3,7 END