I'm trying to rewrite this snippet to work in visual studio, but I clearly don't understand how to use the purpose of the colons and the meaning of __volatile__,
may you offer some help :)?
__asm__ __volatile__ (
"mov %0, %%edi\n"
"xor %%eax, %%eax\n"
"xor %%ecx, %%ecx\n"
"dec %%ecx\n"
"repne scasb\n"
"sub %%ecx, %%eax\n"
"dec %%eax\n"
:
: "m" (src)
: "memory", "%ecx", "%edi", "%eax");
Thanks!
The two inline assemblers are completely different. The Visual Studio inline assembler is more primitive but easier to use. In VS:
Your code doesn't have any output operators (after the first colon), so I don't see how it can have any effect. But suppose the eax register is to be saved in the src variable at the end. Then you want something like this:
char* src;
...
__asm {
mov edi,src
xor eax,eax
xor ecx,ecx
dec ecx
repne scasb
sub eax,ecx
dec eax
mov src,eax // save result
}
By the way, it looks non-optimal to me. All that business with eax could be done by not ecx, if I understand the code correctly:
__asm {
mov edi,src
xor al,al
xor ecx,ecx
dec ecx
repne scasb
not ecx
mov src,ecx // save result
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With