相关疑难解决方法(0)

组装时大吃一惊

我在汇编中实现了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)

谢谢

linux x86 assembly nasm strlen

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

assembly ×1

linux ×1

nasm ×1

strlen ×1

x86 ×1