From c7f7e10e74b0213a28b14494f51c8e01343f141b Mon Sep 17 00:00:00 2001 From: Raphael Date: Sat, 13 Dec 2025 13:36:08 +0100 Subject: [PATCH] feat(strcpy): adding my own strcpy version --- src/ft_strcpy.s | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/ft_strcpy.s diff --git a/src/ft_strcpy.s b/src/ft_strcpy.s new file mode 100644 index 0000000..de5cd90 --- /dev/null +++ b/src/ft_strcpy.s @@ -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