PROWAREtech

articles » current » assembly » x64 » procedures » strlen

x64 Assembly: strlen Procedure

Find ASCII string length using x86-64 (64-bit) assembly.

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

This 64-bit procedure, strlen_asm_x64, returns the length of a C-string.


TITLE 'extern "C" unsigned long long strlen_asm_x64(const char *string);'

PUBLIC	strlen_asm_x64

_TEXT	SEGMENT
strlen_asm_x64 PROC

	push rdi
	mov  rdi, rcx ; *string
	mov  rcx, 0FFFFFFFFFFFFFFFFh
	xor  rax, rax
	cld
	repne scasb
	xor  rcx, 0FFFFFFFFFFFFFFFFh
	dec  rcx
	mov  rax, rcx
	pop  rdi

	ret
	
strlen_asm_x64 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