Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %include "io.inc"
- section .rodata
- yes db 'Yes', 0
- no db 'No', 0
- section .text
- global CMAIN
- CMAIN:
- mov ebp, esp
- GET_UDEC 4, eax
- GET_UDEC 4, ebx
- push ebx
- push eax
- call palindrome
- xor eax, eax
- mov esp, ebp
- ret
- ; n
- ; m
- palindrome:
- push ebp
- mov ebp, esp
- mov ecx, [ebp + 12]
- push dword [ebp + 8]
- .L1:
- jecxz .L2
- xchg esi, ecx
- call reverse
- xchg esi, ecx
- add [esp], eax
- dec ecx
- jmp .L1
- .L2:
- call check
- test eax, eax
- jz .else
- PRINT_STRING yes
- NEWLINE
- PRINT_UDEC 4, [esp]
- jmp .endif
- .else:
- PRINT_STRING no
- .endif:
- leave
- ret
- ; m
- check:
- push ebp
- mov ebp, esp
- push dword [ebp + 8]
- call reverse
- cmp eax, dword [ebp + 8]
- jne .else
- mov eax, 1
- jmp .endif
- .else:
- mov eax, 0
- .endif:
- leave
- ret
- ; m
- reverse:
- push ebp
- mov ebp, esp
- push ebx
- push esi
- push edi
- mov eax, [ebp + 8]
- mov ecx, 10
- xor edi, edi
- .loop:
- test eax, eax
- jz .loopend
- xor edx, edx
- div ecx
- mov ebx, edx
- mov esi, eax
- mov eax, edi
- mul ecx
- add eax, ebx
- mov edi, eax
- mov eax, esi
- jmp .loop
- .loopend:
- mov eax, edi
- pop edi
- pop esi
- pop ebx
- pop ebp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement