extern io_get_udec, io_print_udec, io_newline
section .bss
a resd 1000
n resd 1
k resd 1
r resd 1
section .text
global main
f:
push ebp
mov ebp, esp
mov edx, dword [ebp + 8]
xor eax, eax
test edx, edx
jz .E
.L1:
test edx, 1
jnz .L2
shr edx, 1
jmp .L1
.L2:
shr edx, 1
jz .E
.L3:
test edx, 1
jnz .L4
inc eax
.L4:
shr edx, 1
jnz .L3
.E:
leave
ret
main:
push ebp
mov ebp, esp
call io_get_udec
mov dword [n], eax
xor ecx, ecx
.L5:
cmp ecx, dword [n]
jge .L6
call io_get_udec
mov dword [a + 4 * ecx], eax
inc ecx
jmp .L5
.L6:
call io_get_udec
mov dword [k], eax
mov dword [r], 0
xor ecx, ecx
.L7:
cmp ecx, dword [n]
jge .L8
push ecx
push dword [a + 4 * ecx]
call f
add esp, 4
pop ecx
cmp eax, dword [k]
jne .L9
inc dword [r]
.L9:
inc ecx
jmp .L7
.L8:
mov eax, dword [r]
call io_print_udec
call io_newline
xor eax, eax
leave
ret