Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     char ciag[] = "Hello";
  6.  
  7.     asm volatile(
  8.         ".intel_syntax noprefix;"
  9.  
  10.         "mov eax, %0;"  //pointer to the first char in array
  11.         "xor ebx, ebx;"
  12.  
  13.         "length:"
  14.                 "mov cl, [eax];"
  15.                 "inc eax;"
  16.                 "inc ebx;"
  17.                 "cmp cl, 0;"
  18.                 "jne length;"
  19.  
  20.         "dec eax;" // eax was on 0 of a string, now its on the last char
  21.         "mov edx, eax;" //edx on the last char
  22.         "mov eax, %0;"
  23.         "shr ebx, 1;" //divide counter by 2 to get the number of reverse repetition
  24.         "mov esi, edx;"//dont know why but it cant be ebx when MOV CL, EBX - need esi
  25.         "mov edi, eax;"//same
  26.  
  27.         "reverse:"
  28.                 "mov cl, [esi];" //cl has last char
  29.                 "mov di, [edi];" //dl has first char
  30.                 "mov [edi], cl;"
  31.                 "mov [esi], di;"
  32.                 "dec esi;"
  33.                 "inc edi;"
  34.                 "dec ebx;"
  35.                 "jnz reverse;"
  36.         ".att_syntax prefix;"
  37.         :
  38.         :"r" (ciag)
  39.         :"eax", "ebx", "ecx", "edi", "esi"
  40.     );
  41.  
  42.  
  43.     printf("Reverse string: %s\n", ciag);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement