diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile | 41 | ||||
| -rw-r--r-- | ft_read.s | 12 | ||||
| -rw-r--r-- | ft_strcmp.s | 12 | ||||
| -rw-r--r-- | ft_strcpy.s | 13 | ||||
| -rw-r--r-- | ft_strdup.s | 27 | ||||
| -rw-r--r-- | ft_strlen.s | 12 | ||||
| -rw-r--r-- | ft_write.s | 12 | ||||
| -rw-r--r-- | main.c | 50 |
9 files changed, 153 insertions, 29 deletions
@@ -1,3 +1,6 @@ *.o a.out *.dSYM +*.a +test.s +test.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2c4a029 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <marvin@42.fr> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/11/22 02:56:22 by cacharle #+# #+# # +# Updated: 2019/11/22 03:02:47 by cacharle ### ########.fr # +# # +# **************************************************************************** # + +NAME = libasm.a + +CC = gcc +CCFLAGS = -masm=intel -m64 + +ASMSRC = ft_strlen.s ft_strcpy.s ft_strcmp.s ft_write.s ft_read.s ft_strdup.s +ASMOBJ = $(ASMSRC:.s=.o) + +RM = rm -f +LIB = ar rcs + +all: $(NAME) + +$(NAME): $(ASMOBJ) + $(LIB) $(NAME) $(ASMOBJ) + +test: all + $(CC) main.c -L. -lasm + +%.o: %.s + $(CC) $(CCFLAGS) -c -o $@ $< + +clean: + $(RM) $(ASMOBJ) + +fclean: clean + $(RM) $(NAME) + +re: fclean all @@ -1,3 +1,15 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# ft_read.s :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <marvin@42.fr> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/11/22 03:04:44 by cacharle #+# #+# # +# Updated: 2019/11/22 03:04:45 by cacharle ### ########.fr # +# # +# **************************************************************************** # + .globl _ft_read _ft_read: diff --git a/ft_strcmp.s b/ft_strcmp.s index 216b56a..8dd6e01 100644 --- a/ft_strcmp.s +++ b/ft_strcmp.s @@ -1,3 +1,15 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# ft_strcmp.s :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <marvin@42.fr> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/11/22 03:04:38 by cacharle #+# #+# # +# Updated: 2019/11/22 03:04:39 by cacharle ### ########.fr # +# # +# **************************************************************************** # + .globl _ft_strcmp _ft_strcmp: diff --git a/ft_strcpy.s b/ft_strcpy.s index 228ea04..d20476d 100644 --- a/ft_strcpy.s +++ b/ft_strcpy.s @@ -1,3 +1,15 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# ft_strcpy.s :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <marvin@42.fr> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/11/22 03:04:28 by cacharle #+# #+# # +# Updated: 2019/11/22 03:16:19 by cacharle ### ########.fr # +# # +# **************************************************************************** # + .globl _ft_strcpy _ft_strcpy: @@ -10,4 +22,5 @@ _ft_strcpy: inc rcx cmp byte ptr [rbx + rcx], 0 jne FT_STRCPY_LOOP + mov byte ptr [rax + rcx], 0 ret diff --git a/ft_strdup.s b/ft_strdup.s index a10f383..b174239 100644 --- a/ft_strdup.s +++ b/ft_strdup.s @@ -1,11 +1,30 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# ft_strdup.s :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <marvin@42.fr> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/11/22 03:04:32 by cacharle #+# #+# # +# Updated: 2019/11/22 03:16:37 by cacharle ### ########.fr # +# # +# **************************************************************************** # + +.globl _ft_strdup + _ft_strdup: - pop eax - push eax + push rbp + mov rbp, rsp + mov rbx, rdi + mov rax, rbx call _ft_strlen - inc eax - push eax + inc rax + mov rdi, rax call _malloc + mov rdi, rax + mov rsi, rbx call _ft_strcpy + pop rbp ret diff --git a/ft_strlen.s b/ft_strlen.s index c548d73..365fa80 100644 --- a/ft_strlen.s +++ b/ft_strlen.s @@ -1,3 +1,15 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# ft_strlen.s :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <marvin@42.fr> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/11/22 03:04:20 by cacharle #+# #+# # +# Updated: 2019/11/22 03:04:22 by cacharle ### ########.fr # +# # +# **************************************************************************** # + .globl _ft_strlen _ft_strlen: @@ -1,3 +1,15 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# ft_write.s :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <marvin@42.fr> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/11/22 03:04:47 by cacharle #+# #+# # +# Updated: 2019/11/22 03:04:48 by cacharle ### ########.fr # +# # +# **************************************************************************** # + .globl _ft_write _ft_write: @@ -6,52 +6,52 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/22 02:02:24 by cacharle #+# #+# */ -/* Updated: 2019/11/22 02:14:53 by cacharle ### ########.fr */ +/* Updated: 2019/11/22 03:17:39 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include <stdio.h> +#include <stdlib.h> int ft_strlen(char *); char *ft_strcpy(char *dst, const char *src); int ft_strcmp(const char *s1, const char *s2); int ft_write(int, const void*, size_t); int ft_read(int, void*, size_t); - +char *ft_strdup(const char*); int main() { - /* char *a = ""; */ - /* char *b = "a"; */ - - /* printf("%d\n", sizeof(char*)); */ - /* printf("a: %p\n", (void*)a); */ - /* printf("b: %p\n", (void*)a); */ - /* extern ft_strlen("bonjour"); */ - /* printf("%d\n", ft_strlen(a)); */ - /* printf("%d\n", ft_strlen(b)); */ - /* printf("%d\n", ft_strlen("bonjour")); */ - - - /* char c[32] = "bon"; */ - /* char *d = "bonjourasdfasdf"; */ - /* */ - /* printf("%s\n", ft_strcpy(c, d)); */ - /* printf("%s\n", c); */ - + char *a = ""; + char *b = "a"; + printf("%d\n", sizeof(char*)); + printf("a: %p\n", (void*)a); + printf("b: %p\n", (void*)a); + printf("%d\n", ft_strlen(a)); + printf("%d\n", ft_strlen(b)); + printf("%d\n", ft_strlen("bonjour")); + + char c[32] = "bon"; + char *d = "bonjourasdfasdf"; + printf("%s\n", ft_strcpy(c, d)); + printf("%s\n", c); char *e = "\x03"; char *f = "\x02"; printf("%d\n", ft_strcmp(e, f)); printf("%d\n", strcmp(e, f)); - /* ft_write(1, "bon\n", 4); */ + ft_write(1, "bon\n", 4); + + char g[32]; + int ret = ft_read(0, g, 2); + g[ret] = 0; + printf("%s\n", g); - /* char g[32]; */ - /* int ret = ft_read(0, g, 2); */ - /* g[ret] = 0; */ - /* printf("%s\n", g); */ + char *h = ft_strdup("bonjour"); + printf("%s\n", h); + free(h); return 0; } |
