Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void reverse_string(char *str)
- {
- __asm
- (
- "mov ecx, 0xFFFFFFFF\n\t"
- "xor eax, eax\n\t"
- "mov edi, %0\n\t"
- "repne scasb\n\t"
- "not ecx\n\t"
- "sub ecx, 1\n\t"
- "mov esi, %0\n\t"
- "mov edi, ecx\n\t"
- "dec edi\n\t"
- "lea edi, [esi+edi]\n\t"
- "swap_bytes:\n\t"
- "mov al, [esi]\n\t"
- "mov bl, [edi]\n\t"
- "mov [esi], bl\n\t"
- "mov [edi], al\n\t"
- "inc esi\n\t"
- "dec edi\n\t"
- "cmp esi, edi\n\t"
- "jb swap_bytes\n\t"
- :"+m"(str)::"memory", "cc", "eax", "ecx", "esi", "edi", "al", "bl"
- );
- }
- int main(void)
- {
- char string[] = "michal bialek";
- printf("%s\n", string);
- reverse_string(string);
- printf("%s\n", string);
- printf("%c\n", string[0]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement