diff --git a/Makefile b/Makefile index c29620a..0a3024e 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,9 @@ SHARED_LIB=lib$(LIB_NAME).so SRCS=$(SRC_DIR)/ft_strlen.asm \ $(SRC_DIR)/ft_strcpy.asm \ $(SRC_DIR)/ft_strcmp.asm \ - $(SRC_DIR)/ft_write.asm + $(SRC_DIR)/ft_write.asm \ + $(SRC_DIR)/ft_read.asm \ + $(SRC_DIR)/ft_strdup.asm OBJS=$(patsubst $(SRC_DIR)/%.asm,$(OBJ_DIR)/%.o,$(SRCS)) DEPS=$(OBJS:.o=.d) diff --git a/src/ft_read.asm b/src/ft_read.asm new file mode 100644 index 0000000..65030d9 --- /dev/null +++ b/src/ft_read.asm @@ -0,0 +1,22 @@ +global ft_read +extern __errno_location +section .text + + +ft_read: + mov eax, 0 + syscall + + test rax, rax + js .done + + neg rax + mov edi, eax + call __errno_location wrt ..plt + mov dword [rax], edi + mov eax, -1 + + +.done: + ret + diff --git a/src/ft_strdup.asm b/src/ft_strdup.asm new file mode 100644 index 0000000..0036f76 --- /dev/null +++ b/src/ft_strdup.asm @@ -0,0 +1,22 @@ +global ft_strdup +extern malloc +extern ft_strlen +extern ft_strcpy +section .text + +ft_strdup: + call ft_strlen wrt ..plt + inc rax + mov r10, rdi + mov rdi, rax + + call malloc wrt ..plt + test rax, rax + je .done + + mov rdi, rax + mov rsi, r10 + call ft_strcpy wrt ..plt + +.done: + ret