strlen 模拟

; Prototype:
;
ax strlen(char *str)
;
Param:
;
str: The address of a null terminated string.
;
Return:
;
eax: The length of string, excluding null character.; Function own the stack and response for pop stack.
strlen PROC NEAR32
push ebp
mov ebp, esp
pushf
push ebx

; Initialize
mov eax, 0
mov ebx, [ebp + 8]

; Count
while_strlen:
cmp BYTE PTR [ebx], 0
jz exit_strlen
inc ebx
inc eax
jmp while_strlen

; Exit
exit_strlen:
pop ebx
popf
pop ebp
ret 4
strlen ENDP

  

posted @ 2011-08-28 21:41  walfud  阅读(230)  评论(0编辑  收藏  举报