Advertisement
_takumi

assembly convert

Apr 12th, 2022 (edited)
1,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "io.inc"
  2.  
  3. section .rodata
  4.     yes db 'Yes', 0
  5.     no db 'No', 0
  6.  
  7. section .text
  8. global CMAIN
  9. CMAIN:
  10.     mov ebp, esp
  11.     GET_UDEC 4, eax
  12.     GET_UDEC 4, ebx
  13.     push ebx
  14.     push eax
  15.     call palindrome
  16.     xor eax, eax
  17.     mov esp, ebp
  18.     ret
  19.    
  20. ; n
  21. ; m
  22. palindrome:
  23.     push ebp
  24.     mov ebp, esp
  25.     mov ecx, [ebp + 12]
  26.     push dword [ebp + 8]
  27. .L1:
  28.     jecxz .L2
  29.     xchg esi, ecx
  30.     call reverse
  31.     xchg esi, ecx
  32.     add [esp], eax
  33.     dec ecx
  34.     jmp .L1
  35. .L2:
  36.     call check
  37.     test eax, eax
  38.     jz .else
  39.     PRINT_STRING yes
  40.     NEWLINE
  41.     PRINT_UDEC 4, [esp]
  42.     jmp .endif
  43. .else:
  44.     PRINT_STRING no
  45. .endif:
  46.     leave
  47.     ret
  48.    
  49. ; m
  50. check:
  51.     push ebp
  52.     mov ebp, esp
  53.     push dword [ebp + 8]
  54.     call reverse
  55.     cmp eax, dword [ebp + 8]
  56.     jne .else
  57.     mov eax, 1
  58.     jmp .endif
  59. .else:
  60.     mov eax, 0
  61. .endif:
  62.     leave
  63.     ret
  64.    
  65. ; m
  66. reverse:
  67.     push ebp
  68.     mov ebp, esp
  69.     push ebx
  70.     push esi
  71.     push edi
  72.     mov eax, [ebp + 8]
  73.     mov ecx, 10
  74.     xor edi, edi
  75. .loop:
  76.     test eax, eax
  77.     jz .loopend
  78.     xor edx, edx
  79.     div ecx
  80.     mov ebx, edx
  81.     mov esi, eax
  82.     mov eax, edi
  83.     mul ecx
  84.     add eax, ebx
  85.     mov edi, eax
  86.     mov eax, esi
  87.     jmp .loop
  88. .loopend:
  89.     mov eax, edi
  90.     pop edi
  91.     pop esi
  92.     pop ebx
  93.     pop ebp
  94.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement