section .data
fmt_in db "%s %d %d", 0
fmt_out db "%-*s|%*d|%*d", 10, 0
section .bss
arr resd 1
size resd 1
cap resd 1
buf resb 1000005
pen resd 1
sol resd 1
maxn resd 1
maxp resd 1
maxs resd 1
section .text
extern malloc, realloc, free, scanf, printf, qsort, strlen, strcpy, strcmp
global main
digits:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov ecx, 1
.d1:
cmp eax, 9
jle .d2
xor edx, edx
mov ebx, 10
div ebx
inc ecx
jmp .d1
.d2:
mov eax, ecx
pop ebp
ret
cmp:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov edx, [ebp+12]
mov ecx, [eax+12]
mov ebx, [edx+12]
cmp ecx, ebx
jne .c1
mov ecx, [eax+8]
mov ebx, [edx+8]
cmp ecx, ebx
jne .c2
push dword [edx]
push dword [eax]
call strcmp
add esp, 8
jmp .cend
.c1:
mov eax, ebx
sub eax, ecx
jmp .cend
.c2:
mov eax, ecx
sub eax, ebx
.cend:
pop ebp
ret
main:
push ebp
mov ebp, esp
mov dword [arr], 0
mov dword [size], 0
mov dword [cap], 0
mov dword [maxn], 0
mov dword [maxp], 0
mov dword [maxs], 0
.read_loop:
push sol
push pen
push buf
push fmt_in
call scanf
add esp, 16
cmp eax, 3
jne .after_read
mov eax, [size]
mov ebx, [cap]
cmp eax, ebx
jne .no_resize
cmp ebx, 0
jne .grow
mov ebx, 4
jmp .alloc_new
.grow:
shl ebx, 1
.alloc_new:
mov [cap], ebx
mov ecx, ebx
shl ecx, 4
push ecx
push dword [arr]
call realloc
add esp, 8
test eax, eax
jz .exit
mov [arr], eax
.no_resize:
push buf
call strlen
add esp, 4
mov esi, eax
push esi
inc dword [esp]
call malloc
add esp, 4
test eax, eax
jz .exit
mov edi, eax
push buf
push edi
call strcpy
add esp, 8
mov eax, [arr]
mov ecx, [size]
mov edx, ecx
shl edx, 4
add eax, edx
mov [eax], edi
mov [eax+4], esi
mov ebx, [pen]
mov [eax+8], ebx
mov ebx, [sol]
mov [eax+12], ebx
mov eax, esi
cmp eax, [maxn]
jle .s1
mov [maxn], eax
.s1:
push dword [pen]
call digits
add esp, 4
cmp eax, [maxp]
jle .s2
mov [maxp], eax
.s2:
push dword [sol]
call digits
add esp, 4
cmp eax, [maxs]
jle .s3
mov [maxs], eax
.s3:
inc dword [size]
jmp .read_loop
.after_read:
push cmp
push 16
push dword [size]
push dword [arr]
call qsort
add esp, 16
xor ecx, ecx
.print_loop:
cmp ecx, [size]
jge .end_print
mov eax, [arr]
mov edx, ecx
shl edx, 4
add eax, edx
push dword [eax+12]
push dword [maxs]
push dword [eax+8]
push dword [maxp]
push dword [eax]
push dword [maxn]
push fmt_out
call printf
add esp, 28
inc ecx
jmp .print_loop
.end_print:
xor ecx, ecx
.free_loop:
cmp ecx, [size]
jge .end_free
mov eax, [arr]
mov edx, ecx
shl edx, 4
add eax, edx
push dword [eax]
call free
add esp, 4
inc ecx
jmp .free_loop
.end_free:
push dword [arr]
call free
add esp, 4
.exit:
mov eax, 0
leave
ret