You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
4.3 KiB

.data
.globl buf
.p2align 2
buf:
.zero 800
.text
.globl merge_sort
.p2align 2
merge_sort:
.L.merge_sort.0:
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #64
str x21, [sp, #0]
str x22, [sp, #8]
str x20, [sp, #16]
str x19, [sp, #24]
str x23, [sp, #32]
mov w19, w0
mov w20, w1
mov w8, #1
add w8, w19, w8
cmp w8, w20
b.ge .L.merge_sort.1
b .L.merge_sort.2
.L.merge_sort.1:
ldr x21, [sp, #0]
ldr x22, [sp, #8]
ldr x20, [sp, #16]
ldr x19, [sp, #24]
ldr x23, [sp, #32]
add sp, sp, #64
ldp x29, x30, [sp], #16
ret
.L.merge_sort.2:
add w8, w19, w20
mov w9, #2
add w9, w8, #1
cmp w8, #0
csel w8, w9, w8, lt
asr w23, w8, #1
mov w0, w19
mov w1, w23
bl merge_sort
mov w0, w23
mov w1, w20
bl merge_sort
mov w15, w19
mov w22, w23
mov w21, w19
mov w12, w23
b .L.merge_sort.3
.L.merge_sort.3:
cmp w21, w12
b.lt .L.merge_sort.6
b .L.merge_sort.5
.L.merge_sort.4:
adrp x8, buf
add x8, x8, :lo12:buf
sxtw x9, w21
lsl x9, x9, #2
add x9, x8, x9
ldr w10, [x9]
sxtw x9, w22
lsl x9, x9, #2
add x8, x8, x9
ldr w8, [x8]
cmp w10, w8
b.lt .L.merge_sort.7
b .L.merge_sort.8
.L.merge_sort.5:
mov w11, w15
mov w10, w22
mov w15, w21
b .L.merge_sort.10
.L.merge_sort.6:
cmp w22, w20
b.lt .L.merge_sort.4
b .L.merge_sort.5
.L.merge_sort.7:
mov w8, #100
add w11, w8, w15
adrp x10, buf
add x10, x10, :lo12:buf
sxtw x8, w21
lsl x8, x8, #2
add x8, x10, x8
ldr w9, [x8]
sxtw x8, w11
lsl x8, x8, #2
add x8, x10, x8
str w9, [x8]
mov w8, #1
add w8, w21, w8
mov w10, w22
mov w9, w8
b .L.merge_sort.9
.L.merge_sort.8:
mov w8, #100
add w11, w8, w15
adrp x10, buf
add x10, x10, :lo12:buf
sxtw x8, w22
lsl x8, x8, #2
add x8, x10, x8
ldr w9, [x8]
sxtw x8, w11
lsl x8, x8, #2
add x8, x10, x8
str w9, [x8]
mov w8, #1
add w8, w22, w8
mov w10, w8
mov w9, w21
b .L.merge_sort.9
.L.merge_sort.9:
mov w8, #1
add w8, w15, w8
mov w15, w8
mov w22, w10
mov w21, w9
b .L.merge_sort.3
.L.merge_sort.10:
cmp w15, w12
b.lt .L.merge_sort.11
b .L.merge_sort.12
.L.merge_sort.11:
mov w8, #100
add w8, w8, w11
adrp x21, buf
add x21, x21, :lo12:buf
sxtw x9, w15
lsl x9, x9, #2
add x9, x21, x9
ldr w9, [x9]
sxtw x8, w8
lsl x8, x8, #2
add x8, x21, x8
str w9, [x8]
mov w8, #1
add w9, w15, w8
add w8, w11, w8
mov w11, w8
mov w15, w9
b .L.merge_sort.10
.L.merge_sort.12:
mov w12, w11
b .L.merge_sort.13
.L.merge_sort.13:
cmp w10, w20
b.lt .L.merge_sort.14
b .L.merge_sort.15
.L.merge_sort.14:
mov w8, #100
add w8, w8, w12
adrp x9, buf
add x9, x9, :lo12:buf
sxtw x11, w10
lsl x11, x11, #2
add x11, x9, x11
ldr w11, [x11]
sxtw x8, w8
lsl x8, x8, #2
add x8, x9, x8
str w11, [x8]
mov w8, #1
add w9, w10, w8
add w8, w12, w8
mov w12, w8
mov w10, w9
b .L.merge_sort.13
.L.merge_sort.15:
mov w8, w19
b .L.merge_sort.16
.L.merge_sort.16:
cmp w8, w20
b.lt .L.merge_sort.17
b .L.merge_sort.18
.L.merge_sort.17:
mov w9, #100
add w9, w9, w8
adrp x11, buf
add x11, x11, :lo12:buf
sxtw x9, w9
lsl x9, x9, #2
add x9, x11, x9
ldr w10, [x9]
sxtw x9, w8
lsl x9, x9, #2
add x9, x11, x9
str w10, [x9]
mov w9, #1
add w8, w8, w9
b .L.merge_sort.16
.L.merge_sort.18:
ldr x21, [sp, #0]
ldr x22, [sp, #8]
ldr x20, [sp, #16]
ldr x19, [sp, #24]
ldr x23, [sp, #32]
add sp, sp, #64
ldp x29, x30, [sp], #16
ret
.text
.globl main
.p2align 2
main:
.L.main.0:
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #48
str x21, [sp, #0]
str x20, [sp, #8]
str x19, [sp, #16]
adrp x19, buf
add x19, x19, :lo12:buf
mov x0, x19
bl getarray
mov w20, w0
mov w21, #0
mov w0, w21
mov w1, w20
bl merge_sort
mov w0, w20
mov x1, x19
bl putarray
mov w0, w21
ldr x21, [sp, #0]
ldr x20, [sp, #8]
ldr x19, [sp, #16]
add sp, sp, #48
ldp x29, x30, [sp], #16
ret