.section ".data"
.global in
.type in,#object
.align 4
in:
.word 10
.word 32
.word -1
.word 567
.word 3
.word 18
.word 1
.word -51
.word 789
.word 0
.global main
.section ".text"
.align 4
.proc 4
main:
save %sp,-96,%sp
set in,%o0
set 10,%o1
call sort; nop
mov %g0,%i5
ba .L5; nop
.L2:
sll %i5,2,%i4
set in,%i3
ld [%i4+%i3],%o0
call putd; nop
set 10,%o0
call putchar; nop
.L3:
add %i5,1,%i5
.L5:
set 10,%i4
cmp %i5,%i4; blu .L2; nop
mov %g0,%i0
.L1:
ret; restore
.global putd
.align 4
.proc 4
putd:
save %sp,-96,%sp
cmp %i0,0; bge .L7; nop
set 45,%o0
call putchar; nop
neg %i0,%i0
.L7:
mov %i0,%o0
set 10,%o1
call .div,2; nop
cmp %o0,0; be .L9; nop
mov %i0,%o0
set 10,%o1
call .div,2; nop
mov %o0,%i5
call putd; nop
.L9:
mov %i0,%o0
set 10,%o1
call .rem,2; nop
mov %o0,%i5
add %i5,48,%o0
call putchar; nop
.L6:
ret; restore
.global sort
.align 4
.proc 4
sort:
save %sp,-96,%sp
set xx,%i5
st %i0,[%i5]
mov %i0,%o0
mov %g0,%o1
sub %i1,1,%i1
mov %i1,%o2
call quick; nop
.L14:
ret; restore
.global quick
.align 4
.proc 4
quick:
save %sp,-96,%sp
cmp %i1,%i2; bl .L17; nop
ba .L16; nop
.L17:
mov %i0,%o0
mov %i1,%o1
mov %i2,%o2
call partition; nop
mov %o0,%i5
mov %i0,%o0
mov %i1,%o1
sub %i5,1,%o2
call quick; nop
mov %i0,%o0
add %i5,1,%o1
mov %i2,%o2
call quick; nop
.L16:
ret; restore
.global partition
.align 4
.proc 4
partition:
save %sp,-96,%sp
add %i2,1,%i2
mov %i1,%i4
sll %i4,2,%i3
ld [%i3+%i0],%i5
ba .L22; nop
.L21:
add %i1,1,%i1
ba .L25; nop
.L24:
add %i1,1,%i1
.L25:
sll %i1,2,%i3
ld [%i3+%i0],%i3
cmp %i3,%i5; bl .L24; nop
sub %i2,1,%i2
ba .L28; nop
.L27:
sub %i2,1,%i2
.L28:
sll %i2,2,%i3
ld [%i3+%i0],%i3
cmp %i3,%i5; bg .L27; nop
cmp %i1,%i2; bge .L30; nop
sll %i1,2,%i3
add %i3,%i0,%o0
sll %i2,2,%i3
add %i3,%i0,%o1
call exchange; nop
.L30:
.L22:
cmp %i1,%i2; bl .L21; nop
sll %i4,2,%i3
add %i3,%i0,%o0
sll %i2,2,%i3
add %i3,%i0,%o1
call exchange; nop
mov %i2,%i0
.L20:
ret; restore
.global exchange
.align 4
.proc 4
exchange:
save %sp,-96,%sp
set xx,%i4
ld [%i4],%i4
set 4,%i3
sub %i0,%i4,%i2
mov %i2,%o0
mov %i3,%o1
call .div,2; nop
mov %o0,%i2
sub %i1,%i4,%i4
mov %i4,%o0
mov %i3,%o1
call .div,2; nop
mov %o0,%i4
set .L35,%o0
mov %i2,%o1
mov %i4,%o2
call printf; nop
ld [%i0],%i5
ld [%i1],%i4
st %i4,[%i0]
st %i5,[%i1]
.L34:
ret; restore
.section ".bss"
.global xx
.type xx,#object
.common xx,4,4
.section ".rodata"
.align 1
.L35:
.byte 101
.byte 120
.byte 99
.byte 104
.byte 97
.byte 110
.byte 103
.byte 101
.byte 40
.byte 37
.byte 100
.byte 44
.byte 37
.byte 100
.byte 41
.byte 10
.byte 0
