diff --git a/include/libasm.h b/include/libasm.h index eb9e9a9..da5d07e 100644 --- a/include/libasm.h +++ b/include/libasm.h @@ -6,4 +6,5 @@ char *ft_strcpy(char *dest, const char *src); size_t ft_strlen(const char *str); int ft_strcmp( const char *first, const char *second); -ssize_t ft_write(int fd, const void *buf, size_t count); \ No newline at end of file +ssize_t ft_write(int fd, const void *buf, size_t count); +char *ft_strdup(const char *s); \ No newline at end of file diff --git a/src/ft_strdup.asm b/src/ft_strdup.asm new file mode 100644 index 0000000..5c8bc16 --- /dev/null +++ b/src/ft_strdup.asm @@ -0,0 +1,27 @@ +extern ft_strlen +extern malloc +extern ft_strcpy + +section .text + global ft_strdup + ft_strdup: + call ft_strlen + + mov rbx, rdi + mov rdi, rax + + call malloc + + cmp rax, 0 + je error + + mov rdi, rax + mov rsi, rbx + + call ft_strcpy + + ret + + error: + xor rax, rax + ret \ No newline at end of file