diff --git a/libftasm/.gitignore b/libftasm/.gitignore index a7f4f03f..4be147d0 100644 --- a/libftasm/.gitignore +++ b/libftasm/.gitignore @@ -1,3 +1,2 @@ -libft.a +test libfts.a -main diff --git a/libftasm/Makefile b/libftasm/Makefile index 7cd2c123..4032b44f 100644 --- a/libftasm/Makefile +++ b/libftasm/Makefile @@ -18,10 +18,12 @@ NASM = nasm UNAME_S = $(shell uname -s) ifeq ($(UNAME_S),Linux) FLAGS_ASM = -f elf64\ + -D READ=0x0000000\ -DWRITE=0x0000001 endif ifeq ($(UNAME_S),Darwin) FLAGS_ASM = -f macho64\ + -D READ=0x2000003\ -DWRITE=0x2000004 endif @@ -50,6 +52,8 @@ ft_memset.s\ ft_memcpy.s\ ft_strdup.s\ \ +ft_cat.s\ +\ ft_islower.s\ ft_isupper.s\ ft_putchar.s\ diff --git a/libftasm/srcs/ft_cat.s b/libftasm/srcs/ft_cat.s new file mode 100644 index 00000000..d174b885 --- /dev/null +++ b/libftasm/srcs/ft_cat.s @@ -0,0 +1,35 @@ +global _ft_cat +global ft_cat + +extern ft_putchar + +%define STDOUT 1 +%define BUFF_SIZE 10 + +section .bss + buf: resb BUFF_SIZE + +section .text + +_ft_cat: ; void ft_cat(int fd) +ft_cat: + push rdi + lea rsi, [rel buf] + mov rdx, BUFF_SIZE + mov rax, READ ; int read(int fd, void *buf, size_t count) + syscall + cmp rax, 0 + jle end + + mov rdi, STDOUT + mov rdx, rax + mov rax, WRITE ; int write(int fd, const void *buf, size_t count) + syscall + cmp rax, 0 + jl end + + pop rdi + jmp ft_cat +end: + pop rax + ret diff --git a/libftasm/srcs/ft_puts.s b/libftasm/srcs/ft_puts.s index 9b0ecd55..ef32493e 100644 --- a/libftasm/srcs/ft_puts.s +++ b/libftasm/srcs/ft_puts.s @@ -6,7 +6,8 @@ extern ft_putchar %define STDOUT 1 -ft_puts: ; int puts(const char *s) +_ft_puts: ; int puts(const char *s) +ft_puts: push rdi call ft_strlen pop rdi diff --git a/libftasm/srcs/ft_tolower.s b/libftasm/srcs/ft_tolower.s index 7ad14cfe..d2f66dc2 100644 --- a/libftasm/srcs/ft_tolower.s +++ b/libftasm/srcs/ft_tolower.s @@ -3,11 +3,11 @@ global ft_tolower _ft_tolower: ft_tolower: - mov rax, rdi - cmp rdi, 'A' - jl end - cmp rdi, 'Z' - jg end - add rax, 32 + mov rax, rdi + cmp rdi, 'A' + jl end + cmp rdi, 'Z' + jg end + add rax, 32 end: ret diff --git a/libftasm/test.c b/libftasm/test.c index a0774743..7881574c 100644 --- a/libftasm/test.c +++ b/libftasm/test.c @@ -405,16 +405,18 @@ int test_strdup() return (0); } -/* int test_cat(char ** argv) */ -/* { */ -/* ft_putstr(__func__); ft_putstr(":\n"); */ -/* ft_putstr("Wait for a user input:\n"); */ -/* ft_cat(0); */ -/* ft_cat(open(__FILE__, O_RDONLY)); */ -/* ft_cat(open(argv[0], O_RDONLY)); */ -/* ft_cat(-42); */ -/* return (0); */ -/* } */ +int test_cat(char ** argv) +{ + ft_putstr(__func__); ft_putstr(":\n"); + /* ft_putstr("Wait for a user input:\n"); */ + /* ft_cat(0); */ + ft_putstr("\ntest.c:\n"); + ft_cat(open(__FILE__, O_RDONLY)); + ft_putstr("\ntest binary:\n"); + ft_cat(open(argv[0], O_RDONLY)); + ft_cat(-42); + return (0); +} int test_isupper() { @@ -491,12 +493,12 @@ int main(int argc, char **argv) ft_putstr("\nPART BONUS:\n_______\n"); if (test_isupper() || test_islower() || - test_isupper() || - test_putchar()) + test_isupper()) + /* test_putchar()) */ + return (1); + ft_putstr("\nPART 3:\n_______\n"); + if (test_cat(argv)) return (1); - /* ft_putstr("\nPART 3:\n_______\n"); */ - /* /1* if (test_cat(argv)) *1/ */ - /* /1* return (1); *1/ */ puts("\033c\n\033[38;5;117mALL PASSED:\n___________\n\033[0m"); return (0); }