bugger
This commit is contained in:
parent
74a22a407c
commit
8e29c2c26b
6 changed files with 65 additions and 24 deletions
3
libftasm/.gitignore
vendored
3
libftasm/.gitignore
vendored
|
|
@ -1,3 +1,2 @@
|
||||||
libft.a
|
test
|
||||||
libfts.a
|
libfts.a
|
||||||
main
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,12 @@ NASM = nasm
|
||||||
UNAME_S = $(shell uname -s)
|
UNAME_S = $(shell uname -s)
|
||||||
ifeq ($(UNAME_S),Linux)
|
ifeq ($(UNAME_S),Linux)
|
||||||
FLAGS_ASM = -f elf64\
|
FLAGS_ASM = -f elf64\
|
||||||
|
-D READ=0x0000000\
|
||||||
-DWRITE=0x0000001
|
-DWRITE=0x0000001
|
||||||
endif
|
endif
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
FLAGS_ASM = -f macho64\
|
FLAGS_ASM = -f macho64\
|
||||||
|
-D READ=0x2000003\
|
||||||
-DWRITE=0x2000004
|
-DWRITE=0x2000004
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
@ -50,6 +52,8 @@ ft_memset.s\
|
||||||
ft_memcpy.s\
|
ft_memcpy.s\
|
||||||
ft_strdup.s\
|
ft_strdup.s\
|
||||||
\
|
\
|
||||||
|
ft_cat.s\
|
||||||
|
\
|
||||||
ft_islower.s\
|
ft_islower.s\
|
||||||
ft_isupper.s\
|
ft_isupper.s\
|
||||||
ft_putchar.s\
|
ft_putchar.s\
|
||||||
|
|
|
||||||
35
libftasm/srcs/ft_cat.s
Normal file
35
libftasm/srcs/ft_cat.s
Normal 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
|
||||||
|
|
@ -6,7 +6,8 @@ extern ft_putchar
|
||||||
|
|
||||||
%define STDOUT 1
|
%define STDOUT 1
|
||||||
|
|
||||||
ft_puts: ; int puts(const char *s)
|
_ft_puts: ; int puts(const char *s)
|
||||||
|
ft_puts:
|
||||||
push rdi
|
push rdi
|
||||||
call ft_strlen
|
call ft_strlen
|
||||||
pop rdi
|
pop rdi
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@ global ft_tolower
|
||||||
|
|
||||||
_ft_tolower:
|
_ft_tolower:
|
||||||
ft_tolower:
|
ft_tolower:
|
||||||
mov rax, rdi
|
mov rax, rdi
|
||||||
cmp rdi, 'A'
|
cmp rdi, 'A'
|
||||||
jl end
|
jl end
|
||||||
cmp rdi, 'Z'
|
cmp rdi, 'Z'
|
||||||
jg end
|
jg end
|
||||||
add rax, 32
|
add rax, 32
|
||||||
end:
|
end:
|
||||||
ret
|
ret
|
||||||
|
|
|
||||||
|
|
@ -405,16 +405,18 @@ int test_strdup()
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* int test_cat(char ** argv) */
|
int test_cat(char ** argv)
|
||||||
/* { */
|
{
|
||||||
/* ft_putstr(__func__); ft_putstr(":\n"); */
|
ft_putstr(__func__); ft_putstr(":\n");
|
||||||
/* ft_putstr("Wait for a user input:\n"); */
|
/* ft_putstr("Wait for a user input:\n"); */
|
||||||
/* ft_cat(0); */
|
/* ft_cat(0); */
|
||||||
/* ft_cat(open(__FILE__, O_RDONLY)); */
|
ft_putstr("\ntest.c:\n");
|
||||||
/* ft_cat(open(argv[0], O_RDONLY)); */
|
ft_cat(open(__FILE__, O_RDONLY));
|
||||||
/* ft_cat(-42); */
|
ft_putstr("\ntest binary:\n");
|
||||||
/* return (0); */
|
ft_cat(open(argv[0], O_RDONLY));
|
||||||
/* } */
|
ft_cat(-42);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
int test_isupper()
|
int test_isupper()
|
||||||
{
|
{
|
||||||
|
|
@ -491,12 +493,12 @@ int main(int argc, char **argv)
|
||||||
ft_putstr("\nPART BONUS:\n_______\n");
|
ft_putstr("\nPART BONUS:\n_______\n");
|
||||||
if (test_isupper() ||
|
if (test_isupper() ||
|
||||||
test_islower() ||
|
test_islower() ||
|
||||||
test_isupper() ||
|
test_isupper())
|
||||||
test_putchar())
|
/* test_putchar()) */
|
||||||
|
return (1);
|
||||||
|
ft_putstr("\nPART 3:\n_______\n");
|
||||||
|
if (test_cat(argv))
|
||||||
return (1);
|
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");
|
puts("\033c\n\033[38;5;117mALL PASSED:\n___________\n\033[0m");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue