Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: asm_sort.s
- Revision:
- 2:968db132481b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/asm_sort.s Sat Jan 04 12:34:04 2020 +0000
@@ -0,0 +1,33 @@
+ AREA asm_func, CODE, READONLY
+ EXPORT asm_sort
+asm_sort
+ PUSH {R2, R3, R4, R5, LR} ; Some code goes here
+outer_loop
+ LDR R2, =0x0 ;first index
+ LDR R3, =0x1 ;second index
+ SUB R1, R1, #1 ;size of array intervaled minus one
+ CMP R1, #1 ;make sure interval has at least two elements
+ BLT done
+inner_loop
+ CMP R3, R1 ;compare interval
+ BGT loop_exit ;make sure to restart loop if at the end of first pass
+ LDR R4, [R0, R2, LSL #2] ;numbers[first] into R4
+ LDR R5, [R0, R3, LSL #2] ;number[second] into R5
+ CMP R4, R5 ;compare numbers
+ BGT asm_swap ;if out of order swap
+ ADD R2, R2, #1 ;increment index R2
+ ADD R3, R3, #1 ;increment index R3
+ B inner_loop ; go back to keep swapping
+asm_swap
+ STR R4, [R0, R3, LSL #2] ;swap numbers in the array
+ STR R5, [R0, R2, LSL #2]
+ ADD R2, R2, #1 ;increment index
+ ADD R3, R3, #1;increment index
+ B inner_loop ;go back to keep swapping
+loop_exit
+ B outer_loop ;next iteration
+done
+ POP {R2, R3, R4, R5, LR} ;free regs
+ BX LR
+ ALIGN
+ END
\ No newline at end of file