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:
parent
d52f9299cd
commit
42ec5e62e9
1 changed files with 9 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue