Why does this REPNE SCASB implementation of strlen work?
问题 Why does this code work? http://www.int80h.org/strlen/ says that the string address has to be in EDI register for scasb to work, but this assembly function doesn't seem to do this. Assembly code for mystrlen : global mystrlen mystrlen: sub ecx, ecx not ecx sub al, al cld repne scasb neg ecx dec ecx dec ecx mov eax, ecx ret C main: int mystrlen(const char *); int main() { return (mystrlen("1234")); } Compilation: nasm -f elf64 test.asm gcc -c main.c gcc main.o test.o Output: ./a.out echo $? 4