Advertisement
Guest User

Untitled

a guest
Oct 29th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void main() {
  5.     char *x = "abc";
  6.     char *y;
  7.  
  8.     asm volatile (
  9.         ".intel_syntax noprefix;"
  10.         "mov rbx, %1;"
  11.         "xor ecx, ecx;"
  12.         "strLength:"
  13.             "mov al, [rbx];"
  14.             "cmp al, 1;"
  15.             "je xd;"
  16.             "inc rbx;"
  17.             "inc ecx;"
  18.             "jmp strLength;"
  19.  
  20.         "xd:"
  21.             "inc eax;"
  22.             "mov ebx, ecx;"
  23.             "shr ecx, 1;"
  24.             "jz end;"
  25.             "mov rbx, %1;"
  26.  
  27.         "reverseLoop:"
  28.             "mov al, [rbx];"
  29.             "mov bl, [ebx];"
  30.             "mov [rbx], bl;"
  31.             "mov [ebx+1], al;"
  32.             "inc rbx;"
  33.             "dec ebx;"
  34.             "dec ecx;"
  35.             "jnz reverseLoop;"
  36.  
  37.         "end:"
  38.             "mov %0, rbx;"
  39.  
  40.         ".att_syntax prefix;"
  41.         :"=r"(y)
  42.         :"r"(x)
  43.         :"eax","ebx","ecx"
  44.     );
  45.  
  46.     printf("%s\n", y);
  47. }
  48.  
  49. // for (i = 0; i < len/2; ++i) {
  50. //     c = s[i];
  51. //     s[i] = s[len-i-1];
  52. //     s[len-i-1] = c;
  53. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement