Compare commits

..

12 Commits

Author SHA1 Message Date
66cc5c87d4 clean: rename *.asm -> *.s 2025-05-12 14:44:16 +02:00
0b4d562ef9 clean 2024-09-16 16:21:20 +02:00
42b7aab1ae remove bonus 2024-09-16 16:19:38 +02:00
e3b2eb0852 fix: strdup: add 1 to \0 2024-09-11 20:40:52 +02:00
ebf0b0e442 fix: test leak 2024-09-11 20:20:49 +02:00
3effb7caf5 rename: include to headers 2024-09-11 20:15:32 +02:00
27f25d2cea clean 2024-09-05 18:41:46 +02:00
fdc1923211 save register 2024-09-05 18:39:51 +02:00
cbed6c468f add: strdup test 2024-09-05 18:39:38 +02:00
eadf7cde62 add: ft_list_push_front 2024-09-05 18:14:20 +02:00
b1a86b85fe clean: ft_list_size, use right prototype 2024-09-05 16:00:49 +02:00
49283f4227 add: ft_list_size 2024-09-05 13:15:14 +02:00
9 changed files with 58 additions and 4 deletions

View File

@ -24,7 +24,7 @@ all : $(NAME)
test : $(NAME) test : $(NAME)
$(CC) $(CFLAGS) test/test.c $(BUILDDIR)/$(NAME) -o $(BUILDDIR)/test $(CC) $(CFLAGS) test/test.c $(BUILDDIR)/$(NAME) -o $(BUILDDIR)/test
$(BUILDDIR)/test valgrind --leak-check=full $(BUILDDIR)/test
clean : clean :
rm -rf $(OBJDIR) rm -rf $(OBJDIR)

View File

@ -15,6 +15,8 @@ section .text
syscall_failed: syscall_failed:
push rbx
neg rax neg rax
mov rbx, rax mov rbx, rax
@ -22,4 +24,7 @@ section .text
mov [rax], rbx mov [rax], rbx
mov rax, -1 mov rax, -1
pop rbx
ret ret

View File

@ -2,6 +2,8 @@ section .text
global ft_strcmp global ft_strcmp
ft_strcmp: ft_strcmp:
push rbx
xor rcx, rcx xor rcx, rcx
loop: loop:
@ -20,4 +22,7 @@ section .text
out: out:
sub bl, dl sub bl, dl
movsx rax, bl movsx rax, bl
pop rbx
ret ret

View File

@ -5,10 +5,13 @@ extern ft_strcpy
section .text section .text
global ft_strdup global ft_strdup
ft_strdup: ft_strdup:
push rbx
call ft_strlen call ft_strlen
mov rbx, rdi mov rbx, rdi
mov rdi, rax mov rdi, rax
add rdi, 1
call malloc wrt ..plt call malloc wrt ..plt
@ -20,8 +23,13 @@ section .text
call ft_strcpy call ft_strcpy
pop rbx
ret ret
error: error:
xor rax, rax xor rax, rax
pop rbx
ret ret

View File

@ -6,7 +6,9 @@ section .text
loop: loop:
cmp BYTE [rdi + rcx], 0 cmp BYTE [rdi + rcx], 0
je out je out
inc rcx inc rcx
jmp loop jmp loop
out: out:
mov rax, rcx mov rax, rcx

View File

@ -14,10 +14,15 @@ section .text
syscall_failed: syscall_failed:
push rbx
neg rax neg rax
mov rbx, rax mov rbx, rax
call __errno_location wrt ..plt call __errno_location wrt ..plt
mov [rax], rbx mov [rax], rbx
mov rax, -1 mov rax, -1
pop rbx
ret ret

View File

@ -1,6 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include "../include/libasm.h" #include "../headers/libasm.h"
#include "string.h" #include "string.h"
#include <time.h>
#include <stdlib.h>
void test_size_t(size_t expected_value, size_t value) void test_size_t(size_t expected_value, size_t value)
{ {
@ -60,6 +63,30 @@ void multiple_test_strcpy(char *(*own_func)(char *, const char *), const char *
} }
void multiple_test_atoi_base(char *(*own_func)(char *, const char *), const char * const *values[2])
{
char tmp[4096];
for (size_t i = 0; values[i] != NULL; i++)
{
printf("test: %s", values[i]);
printf("\n");
}
}
void multiple_test_strdup(const char * const *values)
{
char *tmp;
for (size_t i = 0; values[i] != NULL; i++)
{
tmp = ft_strdup(values[i]);
test_str(tmp, values[i]);
free(tmp);
printf("\n");
}
}
int main() int main()
{ {
printf("STRLEN\n"); printf("STRLEN\n");
@ -77,6 +104,8 @@ int main()
multiple_test_strcpy(ft_strcpy, strcpy_tests); multiple_test_strcpy(ft_strcpy, strcpy_tests);
printf("\n"); printf("\n");
ft_write(1, "bozo\n", 5); printf("STRDUP\n");
printf("%s\n", ft_strdup("sdsfsd")); const char *strdup_tests[] = {"yo", "", "bonjour", "co\0fgf", NULL};
multiple_test_strdup(strdup_tests);
printf("\n");
} }