Compare commits

..

2 Commits

Author SHA1 Message Date
fdc1923211 save register 2024-09-05 18:39:51 +02:00
cbed6c468f add: strdup test 2024-09-05 18:39:38 +02:00
5 changed files with 40 additions and 2 deletions

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,6 +5,8 @@ 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
@ -20,8 +22,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

@ -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

@ -163,6 +163,19 @@ void multiple_test_push_front()
} }
} }
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");
@ -180,8 +193,11 @@ 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");
/* /*
printf("ATOI_BASE\n"); printf("ATOI_BASE\n");
const char *atoi_base_tests[][2] = {{"0123", ""}, {"0123", "0"}, {"0123", "0123456789"}, {"bonjour", "bonjour"}, {"", ""}, {"bonjour", "salut"}, {"co\0fgf", "co\0fgf"}, NULL}; const char *atoi_base_tests[][2] = {{"0123", ""}, {"0123", "0"}, {"0123", "0123456789"}, {"bonjour", "bonjour"}, {"", ""}, {"bonjour", "salut"}, {"co\0fgf", "co\0fgf"}, NULL};