我在汇编中实现了strlen的自己的实现,但没有返回正确的值。它返回字符串长度+4。因此。我不明白为什么..我希望任何你...
大会来源:
section .text
[GLOBAL stringlen:] ; C function
stringlen:
push ebp
mov ebp, esp ; setup the stack frame
mov ecx, [ebp+8]
xor eax, eax ; loop counter
startLoop:
xor edx, edx
mov edx, [ecx+eax]
inc eax
cmp edx, 0x0 ; null byte
jne startLoop
end:
pop ebp
ret
Run Code Online (Sandbox Code Playgroud)
和主要例程:
#include <stdio.h>
extern int stringlen(char *);
int main(void)
{
printf("%d", stringlen("h"));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
谢谢