From e4ee25979b7ac1e3cc7fbd73f10f4e508d2ceb4c Mon Sep 17 00:00:00 2001 From: starnakin Date: Wed, 28 Aug 2024 15:47:11 +0200 Subject: [PATCH] add: makefile --- .gitignore | 5 ++-- Makefile | 40 ++++++++++++++++++++++++++++++ ft_strcmp.asm | 19 -------------- ft_strcpy.asm | 14 ----------- src/ft_strcmp.asm | 0 src/ft_strcpy.asm | 19 ++++++++++++++ ft_strlen.asm => src/ft_strlen.asm | 1 + 7 files changed, 62 insertions(+), 36 deletions(-) delete mode 100644 ft_strcmp.asm delete mode 100644 ft_strcpy.asm create mode 100644 src/ft_strcmp.asm create mode 100644 src/ft_strcpy.asm rename ft_strlen.asm => src/ft_strlen.asm (76%) diff --git a/.gitignore b/.gitignore index 04cf95d..4cb7806 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -*.o -a.out -main.c \ No newline at end of file +obj +build \ No newline at end of file diff --git a/Makefile b/Makefile index e69de29..f83278c 100644 --- a/Makefile +++ b/Makefile @@ -0,0 +1,40 @@ +SRCDIR = src +OBJDIR = obj +BUILDDIR = build + +SRC := $(wildcard $(SRCDIR)/*.asm) +OBJ := $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRC)) + +CC = gcc +CFLAGS = + +AS = nasm +ASFLAGS = -f elf64 + +AR = ar +ARFLAGS = + +NAME = libasm.a + +$(OBJDIR)/%.o: $(SRCDIR)/%.asm + mkdir -p $(OBJDIR) + $(AS) $(ASFLAGS) $< -o $@ + +all : $(NAME) + +test : $(NAME) + $(CC) $(CFLAGS) test/test.c $(NAME) -o $(BUILDDIR)/test + $(BUILDDIR)/test + rm -rf $(BUILDDIR)/test + +clean : + rm -rf $(OBJDIR) + +fclean : clean + rm -rf $(BUILDDIR) + +$(NAME) : $(OBJ) + mkdir -p $(BUILDDIR) + $(AR) -rc $(BUILDDIR)/$(NAME) $(OBJ) + +.PHONY: clean fclean test all \ No newline at end of file diff --git a/ft_strcmp.asm b/ft_strcmp.asm deleted file mode 100644 index 1a074fd..0000000 --- a/ft_strcmp.asm +++ /dev/null @@ -1,19 +0,0 @@ - section .text - global ft_strcmp - -ft_strcmp: - mov rax, rdi - mov rbx, rsi -loop: - mov al, [rax] - mov bl, [rbx] - cmp al, bl - jne out - cmp al, 0 - je out - inc rax - inc rbx - jmp loop -out: - sub rax, rbx - ret \ No newline at end of file diff --git a/ft_strcpy.asm b/ft_strcpy.asm deleted file mode 100644 index 4515019..0000000 --- a/ft_strcpy.asm +++ /dev/null @@ -1,14 +0,0 @@ - section .text - global ft_strcpy - -ft_strcpy: - mov rax, 0 -loop: - mov bl, [rsi + rax] - mov [rdi + rax], bl - cmp BYTE [rsi + rax], 0 - je out - inc rax - jmp loop -out: - ret \ No newline at end of file diff --git a/src/ft_strcmp.asm b/src/ft_strcmp.asm new file mode 100644 index 0000000..e69de29 diff --git a/src/ft_strcpy.asm b/src/ft_strcpy.asm new file mode 100644 index 0000000..ba894c4 --- /dev/null +++ b/src/ft_strcpy.asm @@ -0,0 +1,19 @@ + section .text + global ft_strcpy + +ft_strcpy: + mov rcx, 0 +loop: + mov al, [rsi + rcx] + + mov [rdi + rcx], al + + cmp al, 0 + je out + + inc rcx + + jmp loop +out: + mov rax, rcx + ret \ No newline at end of file diff --git a/ft_strlen.asm b/src/ft_strlen.asm similarity index 76% rename from ft_strlen.asm rename to src/ft_strlen.asm index e70693c..131132b 100644 --- a/ft_strlen.asm +++ b/src/ft_strlen.asm @@ -1,3 +1,4 @@ + section .note.GNU-stack noalloc noexec nowrite progbits section .text global ft_strlen