Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 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 ecx, ecx;"
  12.  
  13.         "length:"
  14.                 "mov cl, [eax];"
  15.                 "inc eax;"
  16.                 "inc ecx;"
  17.                 "cmp cl, 0;"
  18.                 "jne length;"
  19.                 "je reverse;"
  20.  
  21.         "dec eax;" // eax was on 0 of a string, now its on the last char
  22.         "mov ebx, eax;" //ebx on the last char
  23.         "mov eax, %0;"
  24.         "shr ecx, 1;"
  25.         "mov esi, ebx;"//dont know why but it cant be ebx when MOV CL, EBX - need esi
  26.         "mov edi, eax;"//same
  27.  
  28.         "reverse:"
  29.                 "mov cl, [esi];" //cl has last char
  30.                 "mov dl, [edi];" //dl has first char
  31.                 "mov [edi], dl;"
  32.                 "mov [esi], cl;"
  33.                 "inc esi;"
  34.                 "dec edi;"
  35.                 "dec ecx;"
  36.                 "jnz reverse;"
  37.         ".att_syntax prefix;"
  38.         :
  39.         :"r" (ciag)
  40.         :"eax", "ebx", "ecx", "edi", "esi"
  41.     );
  42.  
  43.  
  44.     printf("Reverse string: %s\n", ciag);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement