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.

300 lines
5.1 KiB

.data
.globl n
.p2align 2
n:
.word 0
.text
.globl swap
.p2align 2
swap:
.L.swap.0:
stp x29, x30, [sp, #-16]!
mov x29, sp
mov x12, x0
mov w11, w1
mov w10, w2
sxtw x8, w11
lsl x8, x8, #2
add x8, x12, x8
ldr w15, [x8]
sxtw x8, w10
lsl x8, x8, #2
add x8, x12, x8
ldr w9, [x8]
sxtw x8, w11
lsl x8, x8, #2
add x8, x12, x8
str w9, [x8]
sxtw x8, w10
lsl x8, x8, #2
add x8, x12, x8
str w15, [x8]
mov w8, #0
mov w0, w8
ldp x29, x30, [sp], #16
ret
.text
.globl heap_ajust
.p2align 2
heap_ajust:
.L.heap_ajust.0:
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #48
str x19, [sp, #0]
str x20, [sp, #8]
str x21, [sp, #16]
mov x19, x0
mov w8, w1
mov w20, w2
mov w9, #2
lsl w9, w8, #1
mov w10, #1
add w9, w9, w10
mov w11, w9
mov w10, w8
b .L.heap_ajust.1
.L.heap_ajust.1:
mov w8, #1
add w8, w20, w8
cmp w11, w8
b.lt .L.heap_ajust.2
b .L.heap_ajust.3
.L.heap_ajust.2:
cmp w11, w20
b.lt .L.heap_ajust.6
mov w21, w11
b .L.heap_ajust.5
.L.heap_ajust.3:
mov w8, #0
mov w0, w8
ldr x19, [sp, #0]
ldr x20, [sp, #8]
ldr x21, [sp, #16]
add sp, sp, #48
ldp x29, x30, [sp], #16
ret
.L.heap_ajust.4:
mov w8, #1
add w8, w11, w8
mov w21, w8
b .L.heap_ajust.5
.L.heap_ajust.5:
sxtw x8, w10
lsl x8, x8, #2
add x8, x19, x8
ldr w9, [x8]
sxtw x8, w21
lsl x8, x8, #2
add x8, x19, x8
ldr w8, [x8]
cmp w9, w8
b.gt .L.heap_ajust.7
b .L.heap_ajust.8
.L.heap_ajust.6:
sxtw x8, w11
lsl x8, x8, #2
add x8, x19, x8
ldr w9, [x8]
mov w8, #1
add w8, w11, w8
sxtw x8, w8
lsl x8, x8, #2
add x8, x19, x8
ldr w8, [x8]
cmp w9, w8
b.lt .L.heap_ajust.4
mov w21, w11
b .L.heap_ajust.5
.L.heap_ajust.7:
mov w8, #0
mov w0, w8
ldr x19, [sp, #0]
ldr x20, [sp, #8]
ldr x21, [sp, #16]
add sp, sp, #48
ldp x29, x30, [sp], #16
ret
.L.heap_ajust.8:
mov x0, x19
mov w1, w10
mov w2, w21
bl swap
mov w8, w0
mov w8, #2
lsl w8, w21, #1
mov w9, #1
add w8, w8, w9
b .L.heap_ajust.9
.L.heap_ajust.9:
mov w11, w8
mov w10, w21
b .L.heap_ajust.1
.text
.globl heap_sort
.p2align 2
heap_sort:
.L.heap_sort.0:
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #48
str x22, [sp, #0]
str x19, [sp, #8]
str x20, [sp, #16]
str x21, [sp, #24]
mov x21, x0
mov w20, w1
mov w8, #2
add w8, w20, #1
cmp w20, #0
csel w8, w8, w20, lt
asr w9, w8, #1
mov w8, #1
sub w8, w9, w8
mov w22, w8
b .L.heap_sort.1
.L.heap_sort.1:
mov w8, #-1
cmp w22, w8
b.gt .L.heap_sort.2
b .L.heap_sort.3
.L.heap_sort.2:
mov w19, #1
sub w8, w20, w19
mov x0, x21
mov w1, w22
mov w2, w8
bl heap_ajust
mov w8, w0
sub w8, w22, w19
mov w22, w8
b .L.heap_sort.1
.L.heap_sort.3:
mov w8, #1
sub w8, w20, w8
mov w19, w8
b .L.heap_sort.4
.L.heap_sort.4:
mov w8, #0
cmp w19, w8
b.gt .L.heap_sort.5
b .L.heap_sort.6
.L.heap_sort.5:
mov x0, x21
mov w20, #0
mov w1, w20
mov w2, w19
bl swap
mov w8, w0
mov w8, #1
sub w19, w19, w8
mov x0, x21
mov w1, w20
mov w2, w19
bl heap_ajust
mov w8, w0
b .L.heap_sort.4
.L.heap_sort.6:
mov w8, #0
mov w0, w8
ldr x22, [sp, #0]
ldr x19, [sp, #8]
ldr x20, [sp, #16]
ldr x21, [sp, #24]
add sp, sp, #48
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, #80
str x19, [sp, #0]
mov w8, #10
adrp x13, n
str w8, [x13, #:lo12:n]
mov x10, x29
sub x10, x10, #40
mov w8, #4
str w8, [x10]
mov x8, #4
add x8, x10, x8
mov w9, #3
str w9, [x8]
mov x8, #8
add x8, x10, x8
mov w9, #9
str w9, [x8]
mov x8, #12
add x8, x10, x8
mov w9, #2
str w9, [x8]
mov x8, #16
add x9, x10, x8
mov w8, #0
str w8, [x9]
mov x8, #20
add x9, x10, x8
mov w8, #1
str w8, [x9]
mov x8, #24
add x9, x10, x8
mov w8, #6
str w8, [x9]
mov x8, #28
add x9, x10, x8
mov w8, #5
str w8, [x9]
mov x8, #32
add x9, x10, x8
mov w8, #7
str w8, [x9]
mov x8, #36
add x8, x10, x8
mov w9, #8
str w9, [x8]
adrp x13, n
ldr w8, [x13, #:lo12:n]
mov x0, x10
mov w1, w8
bl heap_sort
mov w8, w0
mov w19, w8
b .L.main.1
.L.main.1:
adrp x13, n
ldr w8, [x13, #:lo12:n]
cmp w19, w8
b.lt .L.main.2
b .L.main.3
.L.main.2:
mov x8, x29
sub x8, x8, #40
sxtw x9, w19
lsl x9, x9, #2
add x8, x8, x9
ldr w8, [x8]
mov w0, w8
bl putint
mov w8, #10
mov w0, w8
bl putch
mov w8, #1
add w8, w19, w8
mov w19, w8
b .L.main.1
.L.main.3:
mov w8, #0
mov w0, w8
ldr x19, [sp, #0]
add sp, sp, #80
ldp x29, x30, [sp], #16
ret