feat(strcpy): adding my own strcpy version
This commit is contained in:
parent
4a20982777
commit
c7f7e10e74
1 changed files with 23 additions and 0 deletions
23
src/ft_strcpy.s
Normal file
23
src/ft_strcpy.s
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
segment .note.GNU-stack
|
||||
|
||||
section .text
|
||||
global ft_strcpy
|
||||
|
||||
ft_strcpy:
|
||||
mov rax, rdi ; dest is the return value
|
||||
cmp rdi, 0 ; check if dest is NULL
|
||||
je .exit ; if true return NULL
|
||||
cmp rsi, 0 ; check if dest is NULL
|
||||
je .exit ; if true return NULL
|
||||
xor ecx, ecx ; index set to 0
|
||||
|
||||
.loop:
|
||||
mov dl, BYTE [rsi + rcx] ; take the value of src
|
||||
mov BYTE [rax + rcx], dl ; copy the value of src in dst
|
||||
cmp dl, 0 ; check if the null byte is the last copied
|
||||
je .exit ; return if it was the last byte
|
||||
inc rcx ; increment the index
|
||||
jmp .loop ; restart the loop again
|
||||
|
||||
.exit:
|
||||
ret ; return the rax (dest) value
|
||||
Loading…
Add table
Add a link
Reference in a new issue