PROWAREtech

articles » current » assembly » x86 » procedures » strlen

x86 Assembly: strlen Procedure

Find ASCII string length.

Use MASM for Visual C++ Express Edition 2005 to compile this procedure.

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);'

.386P

.model FLAT

PUBLIC	_strlen_asm

_TEXT	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
_TEXT	ENDS
END

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
CLOSE