Arm 汇编实现 快速排序算法



    area word,code,readonly
    entry
    b start
move
    stmfd   sp!, {r4-r5,lr}
    ldr r4,=0
    cmp r1,r4
    ble _move_return
    add r4,r4,#1
_move_next
        ldr r5,[r0],#4
        str r5,[r2],#4
        add r4,r4,#1
        cmp r4,r1
        ble _move_next
_move_return
    ldmfd   sp!, {r4,r5,pc}
append    
    stmfd   sp!, {r4,lr}
    mov r4,r2,lsl#2
    str r0,[r1,r4]
    ldmfd   sp!, {r4,pc}
sort
    stmfd   sp!, {r4-r10,lr}
    ldr r4,=1
    cmp r1,r4
    ble _sort_return
    mov r4,r0
    mov r5,r1
    mov r6,r2
    mov r7,r3
    ldr r8,=2
    ldr r9,=0
    ldr r10,=0
    ldr r3,[r4],#4
_sort_next
        ldr r0,[r4],#4
        cmp r0,r3
        ble _sort_small_append
_sort_big_append
            add r10,r10,#1
            mov r1,r7
            mov r2,r10
            b _sort_next_append
_sort_small_append
            add r9,r9,#1
            mov r1,r6
            mov r2,r9
            
_sort_next_append
            bl append
        add r8,r8,#1
        cmp r8,r5
        ble _sort_next
    mov r0,r3
            add r9,r9,#1
            mov r1,r6
            mov r2,r9
            bl append
	mov r0,r5,lsl#2
	sub r4,r4,r0
    mov r0,r6
    mov r1,r9
    mov r2,r4
    bl move
 
 
    mov r0,r9,lsl#2
    add r0,r0,#4
    add r2,r4,r0
    mov r0,r7
    mov r1,r10

    bl move
    mov r0,r4
    mov r1,r9
    mov r2,r6
    mov r3,r7
    bl sort
    add r0,r4,r9
    mov r1,r10
    mov r2,r6
    mov r3,r7
    bl sort
_sort_return
    ldmfd sp!,{r4-r10,pc}
    
load_data
    stmfd sp!,{r4,lr}
    ldr r4,=5
    str r4,[r0],#4
    ldr r4,=3
    str r4,[r0],#4
    ldr r4,=2
    str r4,[r0],#4
    ldr r4,=4
    str r4,[r0],#4
    ldmfd sp!,{r4,pc}
start 
    ldr r4,=0x00000
    ldr r5,=4
    ldr r6,=0x00010
    ldr r7,=0x00020
    mov r0,r4
    bl load_data
    mov r0,r4
    mov r1,r5
    mov r2,r6
    mov r3,r7
    bl sort
stop
    mov r0,#0x18   
    ldr r1,=0x20026
    swi 0x123456   
end

汇编实现 快速排序算法

还有点bug日后再调试

    原文作者:排序算法
    原文地址: https://blog.csdn.net/tony123421/article/details/8776046
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞