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