Advertisement
Guest User

Untitled

a guest
Oct 30th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void reverse_string(char *str)
  4. {
  5. __asm
  6. (
  7. "mov ecx, 0xFFFFFFFF\n\t"
  8. "xor eax, eax\n\t"
  9. "mov edi, %0\n\t"
  10. "repne scasb\n\t"
  11. "not ecx\n\t"
  12. "sub ecx, 1\n\t"
  13. "mov esi, %0\n\t"
  14. "mov edi, ecx\n\t"
  15. "dec edi\n\t"
  16. "lea edi, [esi+edi]\n\t"
  17. "swap_bytes:\n\t"
  18. "mov al, [esi]\n\t"
  19. "mov bl, [edi]\n\t"
  20. "mov [esi], bl\n\t"
  21. "mov [edi], al\n\t"
  22. "inc esi\n\t"
  23. "dec edi\n\t"
  24. "cmp esi, edi\n\t"
  25. "jb swap_bytes\n\t"
  26. :"+m"(str)::"memory", "cc", "eax", "ecx", "esi", "edi", "al", "bl"
  27. );
  28. }
  29.  
  30. int main(void)
  31. {
  32. char string[] = "michal bialek";
  33. printf("%s\n", string);
  34. reverse_string(string);
  35. printf("%s\n", string);
  36. printf("%c\n", string[0]);
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement