docs(strlen): adding the strlen documentation

- This comment is here to explain each etape. The main goal of this is
for all people never made assembly can understand
This commit is contained in:
Raphael 2025-12-09 12:34:32 +01:00
parent d52f9299cd
commit 42ec5e62e9
No known key found for this signature in database

View file

@ -4,16 +4,16 @@ section .text
global ft_strlen
ft_strlen:
xor rax, rax
cmp rdi, 0
je .exit
jmp .loop
xor rax, rax ; rax = 0
cmp rdi, 0 ; check rdi is NULL
je .exit ; if rdi NULL exit
jmp .loop ; go to loop
.loop:
cmp BYTE [rdi + rax], 0
je .exit
inc rax
jmp .loop
cmp BYTE [rdi + rax], 0 ; check if the read byte is the end ('\0')
je .exit ; if it's true return to the exit
inc rax ; counter + 1
jmp .loop ; loop again
.exit:
ret
ret ; return rax