I want to calculate length of the word, but I have error. I don't understand why.
int new_strlen(char* word)
{
int len = 0;
__asm__ ("mov ecx, 100\n\t"
"mov esi, %1\n\t"
"mov al, 0\n\t"
"repne scasb\n\t"
"mov %0, 100\n\t"
"sub %0, ecx\n\t"
: "=a"(len)
: "r"(word)
: "%ecx","%esi", "%eax"
);
return len;
}
My error is "‘asm’ operand has impossible constraints".
I attempted to use the __asm{} construct, but it is not available on the x64 architecture.I am compiling a program using the "-masm=intel" flag. My compiler is "g++". Also I attempted to use "volatile" but it useless. Do you have any thoughts on this matter? I would appreciate it if you could share your insights. I am very grateful!
I try anything. Pls, help me
eaxclobbered while also listing it as output using=a. In general if you use amovin inline asm you are probably doing things wrong. Use the constraints to load values. Using100is a strangely limiting choice. Also you know this is 32 bit code, right? Finally, gcc has__builtin_strlenso you don't need to write this by hand even if you don't use libc.