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 .bss
n resd 1
section .text
global main
main:
call io_get_udec
mov ebx, eax
call io_get_udec
mov [n], eax
xor esi, esi
step_loop:
cmp esi, [n]
je check_final
push ebx
call reverse_num
add esp, 4
add ebx, eax
inc esi
jmp step_loop
check_final:
push ebx
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, ebx
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 eax, eax
rev_loop:
test ecx, ecx
jz rev_done
mov edx, 0
mov ebx, 10
div ebx
imul edx, dword 10
add eax, edx
xchg eax, ecx
jmp rev_loop
rev_done:
mov eax, ecx
pop ebp
ret
is_palindrome:
push ebp
mov ebp, esp
push dword [ebp + 8]
call reverse_num
add esp, 4
cmp eax, [ebp + 8]
jne not_pal
mov eax, 1
pop ebp
ret
not_pal:
xor eax, eax
pop ebp
ret