extern io_get_dec
extern io_print_dec
extern io_print_char
section .bss
n resd 1
k resd 1
cnt resd 1
ans resd 1
arr resd 1000
transformation:
push ebp
mov ebp, esp
mov eax, [ebp + 8]
xor ecx, ecx
del:
cmp eax, 0
je end_func
shr eax, 1
jc del
inc ecx
jmp del
end_func:
mov eax, ecx
pop ebp
ret
section .text
global main
main:
call io_get_dec
mov [n], eax
mov dword [cnt], 0
mov edi, arr
get:
mov ecx, [cnt]
cmp ecx, [n]
je finish_read
call io_get_dec
mov [edi], eax
add edi, 4
inc dword [cnt]
jmp get
finish_read:
call io_get_dec
mov [k], eax
mov dword [ans], 0;ответ
mov dword [cnt], 0;счетчик массива
mov edi, arr
check_value:
push dword [edi]
call transformation
add esp, 4
cmp eax, [k]
jne next
inc dword [ans]
next:
add edi, 4
inc dword [cnt]
mov ecx, [cnt]
cmp ecx, [n]
je finish
jmp check_value
finish:
call transformation
mov eax, [ans]
call io_print_dec
ret