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.

253 lines
4.4 KiB

.data
.globl n
.p2align 2
n:
.word 0
.text
.globl counting_sort
.p2align 2
counting_sort:
.L.counting_sort.0:
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #96
str x19, [sp, #0]
str x21, [sp, #8]
str x20, [sp, #16]
mov x11, x0
mov x12, x1
mov w15, w2
mov w8, #0
mov w9, w8
b .L.counting_sort.1
.L.counting_sort.1:
mov w8, #10
cmp w9, w8
b.lt .L.counting_sort.2
b .L.counting_sort.3
.L.counting_sort.2:
mov x8, x29
sub x8, x8, #40
sxtw x10, w9
lsl x10, x10, #2
add x8, x8, x10
mov w10, #0
str w10, [x8]
mov w8, #1
add w8, w9, w8
mov w9, w8
b .L.counting_sort.1
.L.counting_sort.3:
mov w8, #0
mov w20, w8
b .L.counting_sort.4
.L.counting_sort.4:
cmp w20, w15
b.lt .L.counting_sort.5
b .L.counting_sort.6
.L.counting_sort.5:
sxtw x8, w20
lsl x8, x8, #2
add x8, x11, x8
ldr w21, [x8]
sxtw x8, w20
lsl x8, x8, #2
add x8, x11, x8
ldr w8, [x8]
mov x19, x29
sub x19, x19, #40
sxtw x8, w8
lsl x8, x8, #2
add x8, x19, x8
ldr w8, [x8]
mov w10, #1
add w9, w8, w10
sxtw x8, w21
lsl x8, x8, #2
add x8, x19, x8
str w9, [x8]
add w8, w20, w10
mov w20, w8
b .L.counting_sort.4
.L.counting_sort.6:
mov w8, #1
mov w19, w8
b .L.counting_sort.7
.L.counting_sort.7:
mov w8, #10
cmp w19, w8
b.lt .L.counting_sort.8
b .L.counting_sort.9
.L.counting_sort.8:
mov x20, x29
sub x20, x20, #40
sxtw x8, w19
lsl x8, x8, #2
add x8, x20, x8
ldr w9, [x8]
mov w10, #1
sub w8, w19, w10
sxtw x8, w8
lsl x8, x8, #2
add x8, x20, x8
ldr w8, [x8]
add w9, w9, w8
sxtw x8, w19
lsl x8, x8, #2
add x8, x20, x8
str w9, [x8]
add w8, w19, w10
mov w19, w8
b .L.counting_sort.7
.L.counting_sort.9:
mov w9, w15
b .L.counting_sort.10
.L.counting_sort.10:
mov w8, #0
cmp w9, w8
b.gt .L.counting_sort.11
b .L.counting_sort.12
.L.counting_sort.11:
mov w19, #1
sub w10, w9, w19
sxtw x8, w10
lsl x8, x8, #2
add x8, x11, x8
ldr w9, [x8]
sxtw x8, w10
lsl x8, x8, #2
add x8, x11, x8
ldr w8, [x8]
mov x15, x29
sub x15, x15, #40
sxtw x8, w8
lsl x8, x8, #2
add x8, x15, x8
ldr w8, [x8]
sub w8, w8, w19
sxtw x9, w9
lsl x9, x9, #2
add x9, x15, x9
str w8, [x9]
sxtw x8, w10
lsl x8, x8, #2
add x8, x11, x8
ldr w8, [x8]
sxtw x8, w8
lsl x8, x8, #2
add x8, x15, x8
ldr w15, [x8]
sxtw x8, w10
lsl x8, x8, #2
add x8, x11, x8
ldr w9, [x8]
sxtw x8, w15
lsl x8, x8, #2
add x8, x12, x8
str w9, [x8]
mov w9, w10
b .L.counting_sort.10
.L.counting_sort.12:
mov w8, #0
mov w0, w8
ldr x19, [sp, #0]
ldr x21, [sp, #8]
ldr x20, [sp, #16]
add sp, sp, #96
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, #112
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 x9, x29
sub x9, x9, #80
mov x1, x9
mov w2, w8
bl counting_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, #80
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, #112
ldp x29, x30, [sp], #16
ret