PROWARE technologies
PROWARE technologies

strlen in x86 Assembly

This procedure, strlen_asm, returns the length of a C-string. For Unicode strings see wcslen_asm.

TITLE 'extern "C" unsigned strlen_asm(const char *string);'
.686

.model FLAT

PUBLIC	_strlen_asm

_STRLEN	SEGMENT
_strlen_asm PROC NEAR

	push edi
	mov  edi, DWORD PTR [esp+8] ; *string
	mov  ecx, 0FFFFFFFFh
	xor  eax, eax
	cld
	repne scasb
	xor  ecx, 0FFFFFFFFh
	dec  ecx
	mov  eax, ecx
	pop  edi
	
	ret  0
	
_strlen_asm ENDP
_STRLEN	ENDS
END