From bfceb18b34d023640c0bec87a587f0156b06fbca Mon Sep 17 00:00:00 2001 From: Namonay Date: Sun, 23 Jun 2024 20:56:34 +0200 Subject: [PATCH] Added tester and commentary to asm files --- .gitignore | 3 ++- Makefile | 4 ++-- ft_read.s | 20 ++++++++++---------- ft_strcpy.s | 6 +++--- ft_write.s | 2 +- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index c570914..3b7e411 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o *.out *.a -*.c \ No newline at end of file +*.c +.vscode/* \ No newline at end of file diff --git a/Makefile b/Makefile index 1979950..4275ee9 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # 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 -ARFLAG = rc +ARFLAG = rcs .s.o : @printf "\e[1;32m[compiling {"$(CC)"}...]\e[1;00m "$<"\n" diff --git a/ft_read.s b/ft_read.s index 4be3f8a..9d4788b 100644 --- a/ft_read.s +++ b/ft_read.s @@ -2,16 +2,16 @@ global ft_read extern __errno_location ft_read: - mov eax, 0 + mov eax, 0 ; move the syscall code of write (0) into eax (syscall register) syscall - test rax, rax - js .error - ret + test rax, rax ; check if the syscall failed + js .error ; if the syscall failed, jump at .error + ret ; else return .error: - mov rdx, rax - call __errno_location wrt ..plt - neg rdx - mov [rax], rdx - mov rax, -1 - ret \ No newline at end of file + mov rdx, rax ; save rax (return value) into rdx as a temp value + 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 ; invert the return value + mov [rax], rdx ; *errno_value = rdx + mov rax, -1 ; set the return value to -1 + ret ; return \ No newline at end of file diff --git a/ft_strcpy.s b/ft_strcpy.s index e60dd3f..d7d43cb 100644 --- a/ft_strcpy.s +++ b/ft_strcpy.s @@ -12,6 +12,6 @@ ft_strcpy: jmp .cpy .end: - mov byte [rdi + rdx], 0 - mov rax, rdi - ret + mov byte [rdi + rdx], 0 ; dest[rdx] = '\0' + mov rax, rdi ; set dest as the return value + ret ; return diff --git a/ft_write.s b/ft_write.s index 8990255..568906e 100644 --- a/ft_write.s +++ b/ft_write.s @@ -23,4 +23,4 @@ ft_write: neg rdx ; we neg the syscall return value to put it in errno mov [rax], rdx ; *errno_location = value mov rax, -1 ; we return -1 - ret \ No newline at end of file + ret