extern io_get_udec, io_print_udec, io_print_string, io_newline
section .data
yes_str db 'Yes', 0
no_str db 'No', 0
section .text
global main
main:
call io_get_udec
mov esi, eax
call io_get_udec
mov edi, eax
loop_steps:
test edi, edi
jz check_answer
push esi
call reverse_num
add esp, 4
add esi, eax
dec edi
jmp loop_steps
check_answer:
push esi
call is_palindrome
add esp, 4
test eax, eax
jz print_no
mov eax, yes_str
call io_print_string
call io_newline
mov eax, esi
call io_print_udec
ret
print_no:
mov eax, no_str
call io_print_string
ret
reverse_num:
push ebp
mov ebp, esp
mov ecx, [ebp + 8]
xor esi, esi
rev_loop:
test ecx, ecx
jz rev_done
mov eax, ecx
xor edx, edx
mov ebx, 10
div ebx
imul esi, esi, 10
add esi, edx
mov ecx, eax
jmp rev_loop
rev_done:
mov eax, esi
pop ebp
ret
is_palindrome:
push ebp
mov ebp, esp
mov edx, [ebp + 8]
push edx
call reverse_num
add esp, 4
cmp eax, edx
jne not_pal
mov eax, 1
pop ebp
ret
not_pal:
xor eax, eax
pop ebp
ret