From 8a939458e6db6cc8ec33c112f759bde6c1c8b380 Mon Sep 17 00:00:00 2001 From: Namonay Date: Fri, 15 Mar 2024 17:15:37 +0100 Subject: [PATCH] added read, strcmp, strcpy, finished write, added Makefile --- Makefile | 45 +++++++++++++++++++++++++++++++++++++++++++++ ft_read.s | 17 +++++++++++++++++ ft_strcmp.s | 16 ++++++++++++++++ ft_strcpy.s | 16 ++++++++++++++++ ft_write.s | 9 ++++++++- libasm.a | Bin 0 -> 3918 bytes mauvaisdavid.txt | 1 + 7 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 ft_read.s create mode 100644 ft_strcmp.s create mode 100644 ft_strcpy.s create mode 100644 libasm.a create mode 100644 mauvaisdavid.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c11a989 --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +#******************************************************************************# +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: vvaas +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/03/15 14:16:21 by vvaas #+# #+# # +# Updated: 2024/03/15 16:52:30 by vvaas ### ########.fr # +# # +#******************************************************************************# + +NAME = libasm.a + +SRCS = ft_strlen.s \ + ft_write.s \ + ft_read.s \ + ft_strcpy.s \ + ft_strcmp.s \ + +OBJS = ${SRCS:.s=.o} + +CC = nasm + +FLAGS = -f elf64 + +AR = ar + +ARFLAG = rc + +.s.o : + ${CC} $< -o ${<:.s=.o} ${FLAGS} + +all: ${NAME} + +${NAME}: ${OBJS} + ${AR} ${ARFLAGS} ${NAME} ${OBJS} + +clean: + rm -f ${OBJS} + +fclean: clean + rm -f ${NAME} + +re: fclean all diff --git a/ft_read.s b/ft_read.s new file mode 100644 index 0000000..6aed3c1 --- /dev/null +++ b/ft_read.s @@ -0,0 +1,17 @@ +global _read +extern __errno_location + +_read: + mov eax, 0x11 + syscall + test rax, rax + js .error + ret + +.error: + mov ebx, eax + call __errno_location wrt ..plt + neg ebx + mov dword [rax], ebx + mov rax, -1 + ret \ No newline at end of file diff --git a/ft_strcmp.s b/ft_strcmp.s new file mode 100644 index 0000000..bfc9dfa --- /dev/null +++ b/ft_strcmp.s @@ -0,0 +1,16 @@ +extern _strcmp + + +_strcmp: + xor rax, rax + xor rbx, rbx +.count: + mov rax, [rdi + rbx] + sub rax, [rsi + rbx] + cmp rax, 0 + jne .end + inc rbx + jmp .count + +.end: + ret diff --git a/ft_strcpy.s b/ft_strcpy.s new file mode 100644 index 0000000..82dfb2f --- /dev/null +++ b/ft_strcpy.s @@ -0,0 +1,16 @@ +extern _strcpy + +_strcpy: + xor rbx, rbx + +.cpy: + cmp dword [rsi + rbx], 0 + je .end + mov rax, [rsi + rbx] + mov [rdi + rbx], rax + inc rbx + jmp .cpy + +.end: + mov rax, rdi + ret diff --git a/ft_write.s b/ft_write.s index 69f63d4..50a29db 100644 --- a/ft_write.s +++ b/ft_write.s @@ -1,10 +1,17 @@ global _write +extern __errno_location _write: mov eax, 0x1 syscall - jc .error + test rax, rax + js .error ret + .error: + mov ebx, eax + call __errno_location wrt ..plt + neg ebx + mov dword [rax], ebx mov rax, -1 ret \ No newline at end of file diff --git a/libasm.a b/libasm.a new file mode 100644 index 0000000000000000000000000000000000000000..39ce1eb830921aef2280957199f6745e115f2611 GIT binary patch literal 3918 zcmeH~J8u&~5P;|6N5CY+6rg}0u>sKl7aS#q!iv&>u0V)?U?0w*MDk1Li%2S>L==X` zKOw&YQCf0An?6lSq=k!iuued3WY^cJ}d&cP?A7-SYZMY9aG` zc@z+3JNTQ)x%P_UZFy6NZ7#Wiem{`jXNDtoEDSUd1U-1hjwG zBwzF-HS-;w#Ehm-Yw{$@F-=Eeo9(mOJ68MJE7%HKMTa}Kxn~?}I-(0K&vJbo>oET> zdC*1frz+jQmFw&jCc#Tsz0UFXE`aGdTOOFrbv$Lyeub^=s;s4~28yW3PaMAW!n(ym zPWYf)yomvtC*p9AzR)5CsNKNtaqI)quc6!p>cj3wq~u*ogS8MWNetOQ?X?Lk?pWT zZcY;$cf~*k5c9z@g@S&D^!}F6lNYV{aARl`9oMbZiCYV1((k74ZG z7V901olB?>i=CT7ukQ{j72IK=BhwbKp%|AL4UXD?V@ay2oFw)(NIh zqKsJ%CHK>SYdk$wMdVPJ