Skip to content

Commit

Permalink
coucou
Browse files Browse the repository at this point in the history
  • Loading branch information
Reynald LECHAPT committed Mar 10, 2015
0 parents commit 5da6169
Show file tree
Hide file tree
Showing 21 changed files with 716 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Makefile
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
1 change: 1 addition & 0 deletions auteur
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rlechapt
20 changes: 20 additions & 0 deletions ft_bzero.s
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
28 changes: 28 additions & 0 deletions ft_cat.s
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
22 changes: 22 additions & 0 deletions ft_isalnum.s
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
23 changes: 23 additions & 0 deletions ft_isalpha.s
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
19 changes: 19 additions & 0 deletions ft_isascii.s
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
19 changes: 19 additions & 0 deletions ft_isdigit.s
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
20 changes: 20 additions & 0 deletions ft_islower.s
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
19 changes: 19 additions & 0 deletions ft_isprint.s
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
20 changes: 20 additions & 0 deletions ft_isupper.s
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
8 changes: 8 additions & 0 deletions ft_memcpy.s
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
10 changes: 10 additions & 0 deletions ft_memset.s
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
53 changes: 53 additions & 0 deletions ft_puts.s
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
25 changes: 25 additions & 0 deletions ft_strcat.s
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
22 changes: 22 additions & 0 deletions ft_strdup.s
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
17 changes: 17 additions & 0 deletions ft_strlen.s
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
Loading

0 comments on commit 5da6169

Please sign in to comment.