Last active
November 8, 2016 09:33
-
-
Save OsandaMalith/d45f2c34be2d891ae2b63c1bec5a55b2 to your computer and use it in GitHub Desktop.
Manual String Length function in NASM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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