global main
extern scanf
extern printf
section .data
in_fmt db "%d", 0
out_num db "%d", 10, 0
out_i db "%d ", 0
nl db 10, 0
section .bss
n resd 1
x resd 1
mins resd 500000
maxs resd 500000
mincnt resd 1
maxcnt resd 1
section .text
main:
push ebp
mov ebp, esp
push n
push in_fmt
call scanf
add esp, 8
mov eax, [n]
cmp eax, 3
jl print_empty
push x
push in_fmt
call scanf
add esp, 8
mov ebx, [x] ; prev
push x
push in_fmt
call scanf
add esp, 8
mov ecx, [x] ; cur
mov esi, 1 ; index of cur
mov dword [mincnt], 0
mov dword [maxcnt], 0
scan_loop:
mov eax, [n]
dec eax
cmp esi, eax
jge print_answer
push x
push in_fmt
call scanf
add esp, 8
mov edx, [x] ; next
mov eax, ecx
cmp eax, ebx
jge check_max
cmp eax, edx
jge check_max
mov edi, [mincnt]
mov [mins + edi * 4], esi
inc edi
mov [mincnt], edi
jmp shift
check_max:
mov eax, ecx
cmp eax, ebx
jle shift
cmp eax, edx
jle shift
mov edi, [maxcnt]
mov [maxs + edi * 4], esi
inc edi
mov [maxcnt], edi
shift:
mov ebx, ecx
mov ecx, edx
inc esi
jmp scan_loop
print_empty:
mov dword [mincnt], 0
mov dword [maxcnt], 0
print_answer:
push dword [mincnt]
push out_num
call printf
add esp, 8
xor esi, esi
print_mins:
cmp esi, [mincnt]
jge print_mins_end
push dword [mins + esi * 4]
push out_i
call printf
add esp, 8
inc esi
jmp print_mins
print_mins_end:
push nl
call printf
add esp, 4
push dword [maxcnt]
push out_num
call printf
add esp, 8
xor esi, esi
print_maxs:
cmp esi, [maxcnt]
jge print_maxs_end
push dword [maxs + esi * 4]
push out_i
call printf
add esp, 8
inc esi
jmp print_maxs
print_maxs_end:
push nl
call printf
add esp, 4
xor eax, eax
leave
ret