add: makefile
This commit is contained in:
parent
f4f9159a88
commit
e4ee25979b
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
*.o
|
||||
a.out
|
||||
main.c
|
||||
obj
|
||||
build
|
40
Makefile
40
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
|
@ -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
|
@ -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
|
0
src/ft_strcmp.asm
Normal file
0
src/ft_strcmp.asm
Normal file
19
src/ft_strcpy.asm
Normal file
19
src/ft_strcpy.asm
Normal file
@ -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
|
@ -1,3 +1,4 @@
|
||||
section .note.GNU-stack noalloc noexec nowrite progbits
|
||||
section .text
|
||||
global ft_strlen
|
||||
|
Loading…
Reference in New Issue
Block a user