Added tester and commentary to asm files

This commit is contained in:
2024-06-23 20:56:34 +02:00
parent eb33c211ba
commit bfceb18b34
5 changed files with 18 additions and 17 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
*.out *.out
*.a *.a
*.c *.c
.vscode/*

View File

@@ -6,7 +6,7 @@
# By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ # # By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/03/15 14:16:21 by vvaas #+# #+# # # Created: 2024/03/15 14:16:21 by vvaas #+# #+# #
# Updated: 2024/05/23 14:42:18 by vvaas ### ########.fr # # Updated: 2024/06/23 19:55:39 by vvaas ### ########.fr #
# # # #
#******************************************************************************# #******************************************************************************#
@@ -27,7 +27,7 @@ FLAGS = -f elf64
AR = ar AR = ar
ARFLAG = rc ARFLAG = rcs
.s.o : .s.o :
@printf "\e[1;32m[compiling {"$(CC)"}...]\e[1;00m "$<"\n" @printf "\e[1;32m[compiling {"$(CC)"}...]\e[1;00m "$<"\n"

View File

@@ -2,16 +2,16 @@ global ft_read
extern __errno_location extern __errno_location
ft_read: ft_read:
mov eax, 0 mov eax, 0 ; move the syscall code of write (0) into eax (syscall register)
syscall syscall
test rax, rax test rax, rax ; check if the syscall failed
js .error js .error ; if the syscall failed, jump at .error
ret ret ; else return
.error: .error:
mov rdx, rax mov rdx, rax ; save rax (return value) into rdx as a temp value
call __errno_location wrt ..plt call __errno_location wrt ..plt ; call errno_location (put errno pointer into rax) | wrt ..plt means the address of the function will be defined at runtime (needed for libc)
neg rdx neg rdx ; invert the return value
mov [rax], rdx mov [rax], rdx ; *errno_value = rdx
mov rax, -1 mov rax, -1 ; set the return value to -1
ret ret ; return

View File

@@ -12,6 +12,6 @@ ft_strcpy:
jmp .cpy jmp .cpy
.end: .end:
mov byte [rdi + rdx], 0 mov byte [rdi + rdx], 0 ; dest[rdx] = '\0'
mov rax, rdi mov rax, rdi ; set dest as the return value
ret ret ; return