feat: ft_read, ft_strdup
This commit is contained in:
parent
6285fdd11b
commit
31087cec92
3 changed files with 47 additions and 1 deletions
4
Makefile
4
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)
|
||||
|
|
|
|||
22
src/ft_read.asm
Normal file
22
src/ft_read.asm
Normal file
|
|
@ -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
|
||||
|
||||
22
src/ft_strdup.asm
Normal file
22
src/ft_strdup.asm
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue