Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5. char s[] = "afk surr20";
  6. int i = sizeof(s);
  7. int a;
  8. asm volatile(
  9. ".intel_syntax noprefix\n"
  10. "mov eax, %1\n"
  11. "xor ebx, ebx\n"
  12. "xor edx, edx\n"
  13.  
  14.  
  15. "loop:\n"
  16. "mov cl, [eax]\n"
  17. "cmp cl, 0\n"
  18. "jz finish\n"
  19. "cmp cl, ' '\n"
  20. "je loop2\n"
  21. "inc ebx\n"
  22. "inc eax\n"
  23. "inc edx\n"
  24. "jmp loop\n"
  25.  
  26. "loop2:\n"
  27. "mov cl, [eax]\n"
  28. "cmp cl, 0\n"
  29. "jz finish\n"
  30. "inc eax\n"
  31. "inc edx\n"
  32. "jmp loop2\n"
  33.  
  34.  
  35. "finish:\n"
  36. "mov eax, %1\n"
  37. "mov esi, eax\n"
  38. "add eax, ebx\n"
  39. "mov edi, edx\n"
  40. "inc edi\n"
  41.  
  42.  
  43.  
  44. "swap:\n"
  45. "mov al, [edi]\n"
  46. "mov cl, [esi]\n"
  47. "mov [esi], al\n"
  48. "mov [edi], cl\n"
  49. "inc esi\n"
  50. "dec edi\n"
  51. "sub ebx, 1\n"
  52. "cmp ebx, 0\n"
  53. "jg swap\n"
  54.  
  55.  
  56. ".att_syntax prefix\n"
  57. :"=r" (a)
  58. :"r" (s)
  59. : "eax", "ebx", "ecx", "edi", "esi", "edx"
  60. );
  61.  
  62. printf("%s\n", s);
  63.  
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement