Skip to content

Instantly share code, notes, and snippets.

@tuttlem
Created January 7, 2013 21:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuttlem/4478792 to your computer and use it in GitHub Desktop.
Save tuttlem/4478792 to your computer and use it in GitHub Desktop.
strlen - nasm
_strlen:
push rcx ; save and clear out counter
xor rcx, rcx
_strlen_next:
cmp [rdi], byte 0 ; null byte yet?
jz _strlen_null ; yes, get out
inc rcx ; char is ok, count it
inc rdi ; move to next char
jmp _strlen_next ; process again
_strlen_null:
mov rax, rcx ; rcx = the length (put in rax)
pop rcx ; restore rcx
ret ; get out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment