MASM reverse string ( pop push )

  1. include Irvine32.inc
  2. .data
  3. aName byte "reversing a string : ", 0dh, 0ah, 0
  4. nameSize = ($ - aName) - 1              ; length of aName
  5. .code
  6. main proc
  7. mov ecx, nameSize
  8. mov esi, 0
  9. L1:
  10. movzx eax, aName[esi]                   ; put the index into eax
  11. push eax                                ; push into stack
  12. inc esi                                 ; next element
  13. loop L1
  14. mov esi, 0
  15. mov ecx, nameSize
  16. L2:
  17. pop eax                                 ; pop out of stack
  18. mov aName[esi], al
  19. inc esi
  20. loop L2
  21. mov edx, offset aName
  22. call writestring
  23. main endp
  24. end main

before and after

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year