extern io_get_dec, io_print_dec
section .text
global main
main:
call io_get_dec
mov esi, eax
xor ebx, ebx
xor edi, edi
find_loop:
inc edi
push edi
call is_deficient
add esp, 4
test eax, eax
jz find_loop
inc ebx
cmp ebx, esi
jne find_loop
mov eax, edi
call io_print_dec
xor eax, eax
ret
is_deficient:
push ebp
mov ebp, esp
push ebx
push ecx
push edx
push esi
push edi
mov ebx, [ebp + 8]
cmp ebx, 1
jne check_divisors
mov eax, 1
jmp done
check_divisors:
mov esi, 1
mov edi, 2
div_loop:
mov eax, edi
imul eax, edi
cmp eax, ebx
jg finish_check
mov eax, ebx
xor edx, edx
div edi
test edx, edx
jne next_div
add esi, edi
cmp eax, edi
je next_div
add esi, eax
next_div:
inc edi
jmp div_loop
finish_check:
cmp esi, ebx
jl deficient
xor eax, eax
jmp done
deficient:
mov eax, 1
done:
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop ebp
ret