Compare commits
2 Commits
8331a437c0
...
f091b6c53a
Author | SHA1 | Date |
---|---|---|
gbrochar | f091b6c53a | |
gbrochar | bb43c3b95a |
33
Makefile
33
Makefile
|
@ -1,5 +1,7 @@
|
|||
NAME = libasm
|
||||
|
||||
MAKE = make --no-print-directory
|
||||
|
||||
SRC = \
|
||||
ft_strlen.s \
|
||||
ft_strcpy.s \
|
||||
|
@ -7,34 +9,37 @@ SRC = \
|
|||
ft_write.s \
|
||||
ft_read.s \
|
||||
ft_strdup.s \
|
||||
ft_list_size.s \
|
||||
ft_list_push_front.s \
|
||||
ft_list_sort.s \
|
||||
ft_list_remove_if.s \
|
||||
ft_atoi_base.s \
|
||||
|
||||
SRCBONUS = \
|
||||
ft_list_size_bonus.s \
|
||||
ft_list_push_front_bonus.s \
|
||||
ft_list_sort_bonus.s \
|
||||
ft_list_remove_if_bonus.s \
|
||||
ft_atoi_base_bonus.s \
|
||||
|
||||
OBJ = $(SRC:.s=.o)
|
||||
OBJBONUS = $(SRCBONUS:.s=.o)
|
||||
|
||||
%.o:%.s
|
||||
nasm -f elf64 $< -o $@
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
bonus: all
|
||||
bonus: $(OBJ) $(OBJBONUS)
|
||||
ar rcs libasm.a $(OBJ) $(OBJBONUS)
|
||||
|
||||
test_bonus: bonus
|
||||
gcc -Wall -Werror -Wextra -pie main_bonus.c -L . -lasm -o test_bonus
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
ar rcs libasm.a $(OBJ)
|
||||
|
||||
test: $(NAME)
|
||||
gcc -Wall -Werror -Wextra -g ft_list_print.c main.c -L. -lasm -o libasm_unit_tests
|
||||
|
||||
clean:
|
||||
rm $(OBJ)
|
||||
rm -fv $(OBJ) $(OBJBONUS)
|
||||
|
||||
fclean:
|
||||
rm libasm.a
|
||||
rm libasm_unit_tests
|
||||
fclean: clean
|
||||
rm -fv libasm.a
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all test
|
||||
.PHONY: all bonus clean fclean re
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
#include "libasm.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void ft_list_print(t_list *begin_list) {
|
||||
while (begin_list) {
|
||||
printf("%s", (char *)begin_list->data);
|
||||
begin_list = begin_list->next;
|
||||
}
|
||||
}
|
19
ft_strcmp.s
19
ft_strcmp.s
|
@ -1,20 +1,19 @@
|
|||
global ft_strcmp
|
||||
|
||||
ft_strcmp:
|
||||
xor rdx, rdx
|
||||
xor rcx, rcx
|
||||
xor rax, rax
|
||||
xor rdx, rdx
|
||||
.loop:
|
||||
mov al, [rsi + rdx]
|
||||
cmp byte [rdi + rdx], al
|
||||
mov al, [rsi + rcx]
|
||||
cmp byte [rdi + rcx], al
|
||||
jne .done
|
||||
cmp byte [rdi + rdx], 0
|
||||
cmp byte [rdi + rcx], 0
|
||||
je .done
|
||||
inc rdx
|
||||
inc rcx
|
||||
jmp .loop
|
||||
.done:
|
||||
xor rax, rax
|
||||
xor rbx, rbx
|
||||
mov al, byte [rdi + rdx]
|
||||
mov bl, byte [rsi + rdx]
|
||||
sub rax, rbx
|
||||
mov al, byte [rdi + rcx]
|
||||
mov dl, byte [rsi + rcx]
|
||||
sub rax, rdx
|
||||
ret
|
||||
|
|
28
main.c
28
main.c
|
@ -1,28 +0,0 @@
|
|||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "libasm.h"
|
||||
|
||||
void do_nothing(void *data) {
|
||||
(void)data;
|
||||
}
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2) {
|
||||
printf("s1: %ss2: %s", s1, s2);
|
||||
while (*s1 && *s2 && *s1 == *s2) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return *s1 - *s2;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
t_list *l = NULL;
|
||||
ft_list_push_front(&l, "Salut\n");
|
||||
ft_list_print(l);
|
||||
int test = ft_atoi_base("700chmod", "01234567");
|
||||
printf("%d\n", test);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "libasm.h"
|
||||
|
||||
void test_ft_list(void) {
|
||||
t_list *list = NULL;
|
||||
|
||||
assert(ft_list_size(list) == 0);
|
||||
ft_list_push_front(&list, ft_strdup("abc"));
|
||||
ft_list_push_front(&list, ft_strdup("cdb"));
|
||||
ft_list_push_front(&list, ft_strdup("abc"));
|
||||
ft_list_push_front(&list, ft_strdup("egh"));
|
||||
ft_list_push_front(&list, ft_strdup("egb"));
|
||||
ft_list_push_front(&list, ft_strdup("abc"));
|
||||
assert(ft_list_size(list) == 6);
|
||||
ft_list_push_front(&list, ft_strdup("dgb"));
|
||||
ft_list_push_front(&list, ft_strdup("zzz"));
|
||||
assert(ft_list_size(list) == 8);
|
||||
ft_list_remove_if(&list, (void *)"abc", &ft_strcmp, &free);
|
||||
assert(ft_list_size(list) == 5);
|
||||
assert(ft_strcmp(list->data, "zzz") == 0);
|
||||
ft_list_sort(&list, &ft_strcmp);
|
||||
assert(ft_strcmp(list->data, "cdb") == 0);
|
||||
}
|
||||
|
||||
void test_ft_atoi_base(void) {
|
||||
assert(ft_atoi_base("01", "01") == 1);
|
||||
assert(ft_atoi_base("123chmod", "0123456789") == 123);
|
||||
assert(ft_atoi_base("123", "0123456789") == 123);
|
||||
assert(ft_atoi_base("+++++123", "0123456789") == 123);
|
||||
assert(ft_atoi_base("+++++----123", "0123456789") == 123);
|
||||
assert(ft_atoi_base("+-++++----123", "0123456789") == -123);
|
||||
assert(ft_atoi_base("poneyvif", "poneyvif") == 342391);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_ft_list();
|
||||
test_ft_atoi_base();
|
||||
return 0;
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue