start project

This commit is contained in:
2025-03-27 17:11:46 +01:00
commit 589addcb91
9 changed files with 113 additions and 0 deletions

38
Makefile Normal file
View File

@ -0,0 +1,38 @@
NAME ?= libasm.a
SRCS_DIR = srcs
OBJS_DIR = .objs
SRCS_NAMES = ft_strlen.s\
ft_strcpy.s\
ft_strcmp.s\
ft_write.s\
ft_read.s\
ft_strdup.s
SRCS = $(addprefix $(SRCS_DIR)/, $(SRCS_NAMES))
OBJS = $(addprefix $(OBJS_DIR)/, $(SRCS_NAMES:.s=.o))
all: $(NAME)
test: test.c $(NAME)
gcc -o test.o -c test.c
ld tests.c -L. -lasm
$(NAME): $(OBJS_DIR) $(OBJS)
ar rcs $@ $(OBJS)
$(OBJS_DIR):
mkdir -p $(OBJS_DIR)
$(OBJS_DIR)/%.o: $(SRCS_DIR)/%.s
nasm -o $@ $<
clean:
rm -rf $(OBJS_DIR)
fclean: clean
rm -f $(NAME) test
.PHONY: fclean clean all

24
ft_strlen.s Normal file
View File

@ -0,0 +1,24 @@
section .text
global ft_strlen
ft_strlen:
test rdi, rdi
je err
mov rsi, rdi
jmp loop_start
increase_pointer:
lea rsi, [rsi + 1]
loop_start:
mov al, [rsi]
test al, al
jnz increase_pointer
end:
sub rsi, rdi
mov rax, rsi
ret
err:
xor rax, rax
ret

0
srcs/ft_read.s Normal file
View File

0
srcs/ft_strcmp.s Normal file
View File

0
srcs/ft_strcpy.s Normal file
View File

0
srcs/ft_strdup.s Normal file
View File

24
srcs/ft_strlen.s Normal file
View File

@ -0,0 +1,24 @@
section .text
global ft_strlen
ft_strlen:
test rdi, rdi
je err
mov rsi, rdi
jmp loop_start
increase_pointer:
lea rsi, [rsi + 1]
loop_start:
mov al, [rsi]
test al, al
jnz increase_pointer
end:
sub rsi, rdi
mov rax, rsi
ret
err:
xor rax, rax
ret

0
srcs/ft_write.s Normal file
View File

27
tests.c Normal file
View File

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <stdio.h>
size_t ft_strlen(char *str);
void test_strlen(void)
{
int nb_tests;
int passed;
nb_tests = 3;
passed = 0;
if(ft_strlen("hello") == 5)
passed++;
if(ft_strlen("") == 0)
passed++;
if(ft_strlen(NULL) == 0)
passed++;
}
int main(void)
{
test_strlen();
}