Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- char ciag[] = "Hello";
- asm volatile(
- ".intel_syntax noprefix;"
- "mov eax, %0;" //pointer to the first char in array
- "xor ebx, ebx;"
- "length:"
- "mov cl, [eax];"
- "inc eax;"
- "inc ebx;"
- "cmp cl, 0;"
- "jne length;"
- "dec eax;" // eax was on 0 of a string, now its on the last char
- "mov edx, eax;" //edx on the last char
- "mov eax, %0;"
- "shr ebx, 1;" //divide counter by 2 to get the number of reverse repetition
- "mov esi, edx;"//dont know why but it cant be ebx when MOV CL, EBX - need esi
- "mov edi, eax;"//same
- "reverse:"
- "mov cl, [esi];" //cl has last char
- "mov di, [edi];" //dl has first char
- "mov [edi], cl;"
- "mov [esi], di;"
- "dec esi;"
- "inc edi;"
- "dec ebx;"
- "jnz reverse;"
- ".att_syntax prefix;"
- :
- :"r" (ciag)
- :"eax", "ebx", "ecx", "edi", "esi"
- );
- printf("Reverse string: %s\n", ciag);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement