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 ecx, ecx;"
- "length:"
- "mov cl, [eax];"
- "inc eax;"
- "inc ecx;"
- "cmp cl, 0;"
- "jne length;"
- "je reverse;"
- "dec eax;" // eax was on 0 of a string, now its on the last char
- "mov ebx, eax;" //ebx on the last char
- "mov eax, %0;"
- "shr ecx, 1;"
- "mov esi, ebx;"//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 dl, [edi];" //dl has first char
- "mov [edi], dl;"
- "mov [esi], cl;"
- "inc esi;"
- "dec edi;"
- "dec ecx;"
- "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