Skip to content

Instantly share code, notes, and snippets.

@OsandaMalith
Last active November 8, 2016 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OsandaMalith/d45f2c34be2d891ae2b63c1bec5a55b2 to your computer and use it in GitHub Desktop.
Save OsandaMalith/d45f2c34be2d891ae2b63c1bec5a55b2 to your computer and use it in GitHub Desktop.
Manual String Length function in NASM
%if 0
* Title: Manual String Length function
* Author: Osanda Malith (@OsandaMalith)
* Website: https://osandamalith.com
%endif
global _start
section .text
_start:
mov edi, message
call _strlen
mov edx, eax
mov eax, 0x4
mov ebx, 0x1
mov ecx, message
int 0x80
mov eax, 0x1
mov ebx, 0x5
int 0x80
_strlen:
push ebx
push ecx
mov ebx, edi
xor al, al
mov ecx, 0xffffffff
repne scasb ; REPeat while Not Equal [edi] != al
sub edi, ebx ; length = offset of (edi - ebx)
mov eax, edi
pop ebx
pop ecx
ret
section .data
message: db "https://osandamalith.com", 0xa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment