Compare commits

..

No commits in common. "aa95471fb9f586c503387761d8fa509e21388edf" and "391e0a21f90af2625072968d1ff66b9fc9df94b2" have entirely different histories.

10 changed files with 48 additions and 131 deletions

5
.gitignore vendored
View File

@ -1,2 +1,3 @@
obj
build
*.o
a.out
main.c

View File

@ -1,40 +0,0 @@
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

19
ft_strcmp.asm Normal file
View File

@ -0,0 +1,19 @@
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

14
ft_strcpy.asm Normal file
View File

@ -0,0 +1,14 @@
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

12
ft_strlen.asm Normal file
View File

@ -0,0 +1,12 @@
section .text
global ft_strlen
ft_strlen:
mov rax, 0
loop:
cmp BYTE [rdi + rax], 0
je out
inc rax
jmp loop
out:
ret

View File

@ -1,7 +0,0 @@
#pragma once
#include <stddef.h>
char *ft_strcpy(char *dest, const char *src);
size_t ft_strlen(const char *str);
int ft_strcmp( const char *first, const char *second);

View File

View File

@ -1,19 +0,0 @@
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

View File

@ -1,14 +0,0 @@
section .note.GNU-stack noalloc noexec nowrite progbits
section .text
global ft_strlen
ft_strlen:
mov rcx, 0
loop:
cmp BYTE [rdi + rcx], 0
je out
inc rcx
jmp loop
out:
mov rax, rcx
ret

View File

@ -1,49 +0,0 @@
#include <stdio.h>
#include "../include/libasm.h"
#include "string.h"
void test_int(size_t expected_value, size_t value)
{
if (expected_value != value)
printf("[FAILED] %zu != %zu", expected_value, value);
else
printf("[OK]");
}
void test_str(const char *expected_value, const char *value)
{
if (strcmp(expected_value, value) == 0)
printf("[FAILED] %s != %s", expected_value, value);
else
printf("[OK]");
}
void test_int(size_t expected_value, size_t value)
{
if (expected_value != value)
printf("[FAILED] %zu != %zu", expected_value, value);
else
printf("[OK]");
}
void multiple_test_int(size_t (*normal_func)(const char*), size_t (*own_func)(const char*), const char **values)
{
for (size_t i = 0; values[i] != NULL; i++)
{
printf("test: %s ", values[i]);
test_int(normal_func(values[i]), own_func(values[i]));
printf("\n");
}
}
int main()
{
const char *strlen_tests[] = {"yo", "", "bonjour", "co\0fgf", NULL};
multiple_test_int(&strlen, ft_strlen, strlen_tests);
const char *strlen_tests[][2] = {{"bonjour", "bonjour"}, {"", ""}, {"bonjour", "salut"}, {"co\0fgf", "co\0fgf"}, {}, NULL};
multiple_test_int(&strlen, ft_strlen, strlen_tests);
}