Advertisement
Guest User

Reverse

a guest
Oct 30th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. //string reverse
  5.  
  6. int main(){
  7.         char *x = "ala ma kota";
  8.         char *y;
  9.  
  10.         // assembler
  11.         asm volatile(
  12.        ".intel_syntax noprefix;"
  13.        "mov si,OFFSET *x;"
  14.        "cld;"
  15.        "repne scasb;"
  16.        "dec di"
  17.  
  18.         "reverse:"
  19.        "mov al, [si];"
  20.        "mov bl, [di];"
  21.        "mov [si], bl;"
  22.        "mov [di], al;"
  23.        "inc si;"
  24.        "dec di;"
  25.        "cmp di, si;"
  26.        "jae reverse;"
  27.  
  28.         "mov %0, %1;"
  29.  
  30.         ".att_syntax prefix;"
  31.        :"=r"(*y)
  32.        :"r"(*x)
  33.        :"eax","edx","ebx","ecx","di","si"
  34.        );
  35.  
  36.        printf("y=%d\n",*y);
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement