From 13628b49b896a6143d067188d1d9b90c40e38e3d Mon Sep 17 00:00:00 2001 From: lohhiiccc Date: Fri, 12 Jun 2026 16:23:17 +0200 Subject: [PATCH] feat: ft_memcpy --- Makefile | 3 ++- src/ft_memcpy.asm | 17 +++++++++++++++++ src/libasm.h | 5 +++-- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/ft_memcpy.asm diff --git a/Makefile b/Makefile index 5e636aa..6907a9d 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,8 @@ SRCS=$(SRC_DIR)/ft_strlen.asm \ $(SRC_DIR)/ft_strcmp.asm \ $(SRC_DIR)/ft_write.asm \ $(SRC_DIR)/ft_read.asm \ - $(SRC_DIR)/ft_strdup.asm + $(SRC_DIR)/ft_strdup.asm \ + $(SRC_DIR)/ft_memcpy.asm OBJS=$(patsubst $(SRC_DIR)/%.asm,$(OBJ_DIR)/%.o,$(SRCS)) DEPS=$(OBJS:.o=.d) diff --git a/src/ft_memcpy.asm b/src/ft_memcpy.asm new file mode 100644 index 0000000..d4028bc --- /dev/null +++ b/src/ft_memcpy.asm @@ -0,0 +1,17 @@ +global ft_memcpy +section .text + +; rdi: dest +; rsi: src +; rdx: len + +ft_memcpy: + mov rax, rdi + test rdx, rdx + je .done + + cld + mov rcx, rdx + rep movsb +.done: + ret diff --git a/src/libasm.h b/src/libasm.h index 829d0e8..2df3ccd 100644 --- a/src/libasm.h +++ b/src/libasm.h @@ -6,12 +6,13 @@ extern "C" { #endif -size_t ft_strlen(char *str); +size_t ft_strlen(const char *str); char *ft_strcpy(char *dest, const char *src); int ft_strcmp (const char *p1, const char *p2); ssize_t ft_write(int fildes, const void *buf, size_t nbyte); char *strdup(const char *s); -ssize_t read(int fd, void *buf, size_t count); +ssize_t ft_read(int fd, void *buf, size_t count); +void *ft_memcpy(void *dest, const void *src, size_t n); #ifdef __cplusplus }