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.

167 lines
2.8 KiB

.data
.globl n
.p2align 2
n:
.word 0
.text
.globl insertsort
.p2align 2
insertsort:
.L.insertsort.0:
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #32
str x19, [sp, #0]
mov x11, x0
mov w8, #1
mov w10, w8
b .L.insertsort.1
.L.insertsort.1:
adrp x13, n
ldr w8, [x13, #:lo12:n]
cmp w10, w8
b.lt .L.insertsort.2
b .L.insertsort.3
.L.insertsort.2:
sxtw x8, w10
lsl x8, x8, #2
add x8, x11, x8
ldr w8, [x8]
mov w9, #1
sub w9, w10, w9
mov w19, w9
mov w12, w8
b .L.insertsort.4
.L.insertsort.3:
mov w8, #0
mov w0, w8
ldr x19, [sp, #0]
add sp, sp, #32
ldp x29, x30, [sp], #16
ret
.L.insertsort.4:
mov w8, #-1
cmp w19, w8
b.gt .L.insertsort.7
b .L.insertsort.6
.L.insertsort.5:
mov w9, #1
add w8, w19, w9
sxtw x15, w19
lsl x15, x15, #2
add x15, x11, x15
ldr w15, [x15]
sxtw x8, w8
lsl x8, x8, #2
add x8, x11, x8
str w15, [x8]
sub w8, w19, w9
mov w19, w8
b .L.insertsort.4
.L.insertsort.6:
mov w9, #1
add w8, w19, w9
sxtw x8, w8
lsl x8, x8, #2
add x8, x11, x8
str w12, [x8]
add w8, w10, w9
mov w10, w8
b .L.insertsort.1
.L.insertsort.7:
sxtw x8, w19
lsl x8, x8, #2
add x8, x11, x8
ldr w8, [x8]
cmp w12, w8
b.lt .L.insertsort.5
b .L.insertsort.6
.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 x8, x10, x8
mov w9, #0
str w9, [x8]
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]
mov x0, x10
bl insertsort
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