This commit is contained in:
Jack Halford 2017-09-03 11:55:53 +02:00
parent 74a22a407c
commit 8e29c2c26b
6 changed files with 65 additions and 24 deletions

3
libftasm/.gitignore vendored
View file

@ -1,3 +1,2 @@
libft.a
test
libfts.a
main

View file

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

35
libftasm/srcs/ft_cat.s Normal file
View file

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

View file

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

View file

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

View file

@ -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);
}