feat(strcpy): adding my own strcpy version

This commit is contained in:
Raphael 2025-12-13 13:36:08 +01:00
parent 4a20982777
commit c7f7e10e74
No known key found for this signature in database

23
src/ft_strcpy.s Normal file
View 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