added read, strcmp, strcpy, finished write, added Makefile

This commit is contained in:
2024-03-15 17:15:37 +01:00
parent 9316411eb6
commit 8a939458e6
7 changed files with 103 additions and 1 deletions

45
Makefile Normal file
View File

@@ -0,0 +1,45 @@
#******************************************************************************#
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/03/15 14:16:21 by vvaas #+# #+# #
# Updated: 2024/03/15 16:52:30 by vvaas ### ########.fr #
# #
#******************************************************************************#
NAME = libasm.a
SRCS = ft_strlen.s \
ft_write.s \
ft_read.s \
ft_strcpy.s \
ft_strcmp.s \
OBJS = ${SRCS:.s=.o}
CC = nasm
FLAGS = -f elf64
AR = ar
ARFLAG = rc
.s.o :
${CC} $< -o ${<:.s=.o} ${FLAGS}
all: ${NAME}
${NAME}: ${OBJS}
${AR} ${ARFLAGS} ${NAME} ${OBJS}
clean:
rm -f ${OBJS}
fclean: clean
rm -f ${NAME}
re: fclean all

17
ft_read.s Normal file
View File

@@ -0,0 +1,17 @@
global _read
extern __errno_location
_read:
mov eax, 0x11
syscall
test rax, rax
js .error
ret
.error:
mov ebx, eax
call __errno_location wrt ..plt
neg ebx
mov dword [rax], ebx
mov rax, -1
ret

16
ft_strcmp.s Normal file
View File

@@ -0,0 +1,16 @@
extern _strcmp
_strcmp:
xor rax, rax
xor rbx, rbx
.count:
mov rax, [rdi + rbx]
sub rax, [rsi + rbx]
cmp rax, 0
jne .end
inc rbx
jmp .count
.end:
ret

16
ft_strcpy.s Normal file
View File

@@ -0,0 +1,16 @@
extern _strcpy
_strcpy:
xor rbx, rbx
.cpy:
cmp dword [rsi + rbx], 0
je .end
mov rax, [rsi + rbx]
mov [rdi + rbx], rax
inc rbx
jmp .cpy
.end:
mov rax, rdi
ret

View File

@@ -1,10 +1,17 @@
global _write global _write
extern __errno_location
_write: _write:
mov eax, 0x1 mov eax, 0x1
syscall syscall
jc .error test rax, rax
js .error
ret ret
.error: .error:
mov ebx, eax
call __errno_location wrt ..plt
neg ebx
mov dword [rax], ebx
mov rax, -1 mov rax, -1
ret ret

BIN
libasm.a Normal file

Binary file not shown.

1
mauvaisdavid.txt Normal file
View File

@@ -0,0 +1 @@
mauvaisdavid