.section .text;声明为代码段
.globl sort;声明全局变量
sort: ;linux下需要加冒号
mov r2, #0
mov r8, r0
mov r9, r0
loop1:
sub r1, r1, #1
cmp r2, r1
add r1, r1, #1
beq end
mov r6, r2
add r3, r2, #1
loop2:
cmp r3, r1
beq continue1
mov r3, r3, lsl #2
add r8, r8, r3
ldr r5, [r8]
mov r6, r6, lsl #2
add r9, r9, r6
ldr r4, [r9]
cmp r4, r5
bgt exchange
continue2:
sub r8, r8, r3
mov r3, r3, lsr #2
sub r9, r9, r6
mov r6, r6, lsr #2
add r3, r3, #1
b loop2
exchange:
str r4, [r8]
str r5, [r9]
b continue2
continue1:
add r2, r2, #1
b loop1
end:
|