-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Reynald LECHAPT
committed
Mar 10, 2015
0 parents
commit 5da6169
Showing
21 changed files
with
716 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: rlechapt <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2015/03/08 15:15:46 by rlechapt #+# #+# # | ||
# Updated: 2015/03/10 06:24:32 by rlechapt ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
SRC = ft_islower.s \ | ||
ft_isupper.s \ | ||
ft_toupper.s \ | ||
ft_tolower.s \ | ||
ft_isdigit.s \ | ||
ft_isprint.s \ | ||
ft_isascii.s \ | ||
ft_isalnum.s \ | ||
ft_isalpha.s \ | ||
ft_strlen.s \ | ||
ft_puts.s \ | ||
ft_strcat.s \ | ||
ft_bzero.s \ | ||
ft_memset.s \ | ||
ft_memcpy.s \ | ||
ft_strdup.s \ | ||
ft_cat.s | ||
|
||
OBJ = $(SRC:%.s=%.o) | ||
NAME = libfts.a | ||
|
||
all: $(NAME) | ||
|
||
$(NAME): $(OBJ) | ||
ar rc $(NAME) $(OBJ) | ||
ranlib $(NAME) | ||
|
||
%.o: %.s libfts.h | ||
nasm -f macho64 $< | ||
|
||
clean: | ||
rm -f $(OBJ) | ||
|
||
fclean: clean | ||
rm -f $(NAME) | ||
|
||
re: fclean all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rlechapt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
segment .text | ||
global _ft_bzero | ||
|
||
_ft_bzero: | ||
cmp rdi,0 | ||
je end | ||
mov rbx,rdi | ||
xor rcx,rcx | ||
jmp loop | ||
|
||
loop: | ||
cmp rsi,rcx | ||
je end | ||
mov byte [rbx],0 | ||
inc rbx | ||
inc rcx | ||
jmp loop | ||
|
||
end: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
%define BUFF_SIZE 1 | ||
%define SYSCALL(n) 0x2000000 | n | ||
|
||
section .bss | ||
buffer resb BUFF_SIZE | ||
|
||
section .text | ||
global _ft_cat | ||
|
||
_ft_cat: | ||
push rdi | ||
mov rsi, buffer | ||
mov rdx, BUFF_SIZE | ||
mov rax, SYSCALL(3) ; read | ||
syscall | ||
jc end | ||
cmp rax, 0 | ||
je end | ||
mov rdi, 1 | ||
mov rdx, rax | ||
mov rax, SYSCALL(4) ; write | ||
syscall | ||
pop rdi | ||
jmp _ft_cat | ||
|
||
end: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
segment .text | ||
global _ft_isalnum | ||
extern _ft_isalpha | ||
extern _ft_isdigit | ||
|
||
_ft_isalnum: | ||
call _ft_isalpha | ||
cmp rax,1 | ||
je true | ||
call _ft_isdigit | ||
cmp rax,1 | ||
je true | ||
|
||
false: | ||
jmp done | ||
|
||
true: | ||
mov rax,1 | ||
jmp done | ||
|
||
done: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
segment .text | ||
global _ft_isalpha | ||
extern _ft_islower | ||
extern _ft_isupper | ||
|
||
_ft_isalpha: | ||
call _ft_islower | ||
cmp rax, 1 | ||
je true | ||
call _ft_isupper | ||
cmp rax, 1 | ||
je true | ||
|
||
false: | ||
mov rax, 0 | ||
jmp done | ||
|
||
true: | ||
mov rax, 1 | ||
jmp done | ||
|
||
done: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
segment .text | ||
global _ft_isascii | ||
|
||
_ft_isascii: | ||
cmp rdi, 0 | ||
jl false | ||
cmp rdi, 127 | ||
jg false | ||
|
||
true: | ||
mov rax,1 | ||
jmp done | ||
|
||
false: | ||
mov rax,0 | ||
jmp done | ||
|
||
done: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
segment .text | ||
global _ft_isdigit | ||
|
||
_ft_isdigit: | ||
cmp rdi,48 | ||
jl false | ||
cmp rdi,57 | ||
jg false | ||
|
||
true: | ||
mov rax,1 | ||
jmp done | ||
|
||
false: | ||
mov rax,0 | ||
jmp done | ||
|
||
done: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
segment .text | ||
global _ft_islower | ||
|
||
_ft_islower: | ||
cmp rdi,97 | ||
jl false | ||
cmp rdi,122 | ||
jg false | ||
jmp true | ||
|
||
false: | ||
mov rax,0 | ||
jmp done | ||
|
||
true: | ||
mov rax,1 | ||
jmp done | ||
|
||
done: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
segment .text | ||
global _ft_isprint | ||
|
||
_ft_isprint: | ||
cmp rdi, 32 | ||
jl false | ||
cmp rdi, 126 | ||
jg false | ||
|
||
true: | ||
mov rax,1 | ||
jmp done | ||
|
||
false: | ||
mov rax,0 | ||
jmp done | ||
|
||
done: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
segment .text | ||
global _ft_isupper | ||
|
||
_ft_isupper: | ||
cmp rdi, 65 | ||
jl false | ||
cmp rdi, 90 | ||
jg false | ||
jmp true | ||
|
||
true: | ||
mov rax, 1 | ||
jmp done | ||
|
||
false: | ||
mov rax, 0 | ||
jmp done | ||
|
||
done: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
segment .text | ||
global _ft_memcpy | ||
|
||
_ft_memcpy: | ||
mov rax, rdi | ||
mov rcx, rdx | ||
rep movsb | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
segment .text | ||
global _ft_memset | ||
|
||
_ft_memset: | ||
mov rcx, rdx | ||
mov rax, rsi | ||
mov rbx, rdi | ||
rep stosb | ||
mov rax, rbx | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
%define SYSCALL(n) 0x2000000 | n | ||
|
||
section .data | ||
break db 10 | ||
null db "(null)", 0 | ||
|
||
section .text | ||
global _ft_puts | ||
|
||
_ft_puts: | ||
push rbp | ||
mov rbp, rsp | ||
cmp rdi, 0 | ||
jle exit | ||
cmp rdi, 0 | ||
jne suite | ||
mov rdi, null | ||
|
||
suite: | ||
push rdx | ||
push rbx | ||
push rsi | ||
mov rbx, rdi | ||
|
||
loop: | ||
cmp byte [rbx], 0 | ||
je end | ||
mov rdi, 1 | ||
mov rsi, rbx | ||
mov rdx, 1 | ||
mov rax, SYSCALL(4) | ||
syscall | ||
inc rbx | ||
jmp loop | ||
|
||
end: | ||
pop rsi | ||
pop rbx | ||
pop rdx | ||
mov rax, 1 | ||
mov rax, SYSCALL(4) | ||
mov rdi, 1 | ||
mov rsi, break | ||
mov rdx, 1 | ||
syscall | ||
leave | ||
ret | ||
|
||
exit: | ||
mov rax, 0 | ||
mov rsp, rbp | ||
pop rbp | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
section .text | ||
global _ft_strcat | ||
|
||
_ft_strcat: | ||
mov rbx, rdi | ||
mov rcx, rsi | ||
|
||
loop1: | ||
cmp byte [rbx], 0 | ||
je loop2 | ||
inc rbx | ||
jmp loop1 | ||
|
||
loop2: | ||
cmp byte [rcx], 0 | ||
je end | ||
mov al, byte [rcx] | ||
mov byte [rbx], al | ||
inc rcx | ||
inc rbx | ||
jmp loop2 | ||
|
||
end: | ||
mov rax, rdi | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
segment .text | ||
global _ft_strdup | ||
extern _malloc | ||
extern _ft_memcpy | ||
extern _ft_strlen | ||
|
||
_ft_strdup: | ||
mov rbx, rdi | ||
call _ft_strlen | ||
mov rdi, rax | ||
add rdi, 1 | ||
push rdi | ||
call _malloc | ||
cmp rax, 0 | ||
je end | ||
mov rdi, rax | ||
mov rsi, rbx | ||
pop rdx | ||
call _ft_memcpy | ||
|
||
end: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
segment .text | ||
global _ft_strlen | ||
|
||
_ft_strlen: | ||
cmp rdi,0 | ||
je null | ||
mov al,0 | ||
mov rcx,-1 | ||
repne scasb | ||
not rcx | ||
sub rcx,1 | ||
mov rax, rcx | ||
ret | ||
|
||
null: | ||
mov rax,0 | ||
ret |
Oops, something went wrong.