From 0931febe3e178b4e484259c9cdc79ef452208ae7 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 22 Nov 2019 00:11:46 +0100 Subject: ft_strlen.s (i can kinda compile this shit) --- ft_strcpy.s | 12 ++++++------ ft_strlen.s | 24 ++++++++++++------------ main.c | 11 +++++++++++ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ft_strcpy.s b/ft_strcpy.s index 44a098d..2b7bbb9 100644 --- a/ft_strcpy.s +++ b/ft_strcpy.s @@ -2,10 +2,10 @@ _ft_strcpy: pop ax pop bx mov ecx, eax ; copy - FT_STRCPY_LOOP: - mov [ecx], ebx - inc ebx - inc ecx - cmp ebx, 0 - jneq FT_STRCPY_LOOP +FT_STRCPY_LOOP: + mov [ecx], ebx + inc ebx + inc ecx + cmp ebx, 0 + jneq FT_STRCPY_LOOP ret diff --git a/ft_strlen.s b/ft_strlen.s index 32eaf0c..82c0e34 100644 --- a/ft_strlen.s +++ b/ft_strlen.s @@ -1,12 +1,12 @@ -ft_strlen: - pop bx - mov eax, 0h -FT_STRLEN_LOOP: - mov ecx, [ebx] - cmp ecx, 0 - je FT_STRLEN_RET - inc eax - inc ebx - jmp FT_STRLEN_LOOP -FT_STRLEN_RET: - ret +.globl _ft_strlen + + _ft_strlen: + mov rbx, rdi # first argument in rbx + xor rax, rax # rax = 0 + FT_STRLEN_LOOP: + cmp byte ptr [rbx + rax], 0 # compare rbx[rax] and '\0' + je FT_STRLEN_RET + inc rax + jmp FT_STRLEN_LOOP + FT_STRLEN_RET: + ret diff --git a/main.c b/main.c index b1c30b7..fac04a4 100644 --- a/main.c +++ b/main.c @@ -2,11 +2,22 @@ int ft_strlen(char *); +/* extern void test(); */ + int main() { + /* extern say_hi(); */ + char *a = ""; + char *b = "a"; + /* printf("%d\n", sizeof(char*)); */ + /* printf("a: %p\n", (void*)a); */ + /* printf("b: %p\n", (void*)a); */ /* extern ft_strlen("bonjour"); */ + printf("%d\n", ft_strlen(a)); + printf("%d\n", ft_strlen(b)); printf("%d\n", ft_strlen("bonjour")); return 0; } + -- cgit