From b7a3b7140ba1df24453e3148a786db57f31b0715 Mon Sep 17 00:00:00 2001 From: Namonay Date: Wed, 27 Mar 2024 23:02:24 +0100 Subject: [PATCH] bozo --- Makefile | 2 +- ft_strcpy.s | 8 ++++---- ft_strdup.s | 14 +++++++------- ft_write.s | 17 +++++++++++++---- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 1edd1d9..c64e674 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: vvaas +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/03/15 14:16:21 by vvaas #+# #+# # -# Updated: 2024/03/15 16:52:30 by vvaas ### ########.fr # +# Updated: 2024/03/27 17:45:37 by vvaas ### ########.fr # # # #******************************************************************************# diff --git a/ft_strcpy.s b/ft_strcpy.s index 72803c9..e60dd3f 100644 --- a/ft_strcpy.s +++ b/ft_strcpy.s @@ -4,11 +4,11 @@ ft_strcpy: xor rdx, rdx .cpy: - cmp byte [rsi + rdx], 0 + cmp byte [rsi + rdx], 0 ; if src is empty je .end - mov rax, [rsi + rdx] - mov [rdi + rdx], rax - inc rdx + mov rax, [rsi + rdx] ; move src[rdx] to rax + mov word [rdi + rdx], ax ; dest[rdx] = src[rdx] + inc rdx ; rdx++ jmp .cpy .end: diff --git a/ft_strdup.s b/ft_strdup.s index 465b7d5..114039c 100644 --- a/ft_strdup.s +++ b/ft_strdup.s @@ -5,18 +5,18 @@ extern ft_strcpy extern malloc ft_strdup: - call ft_strlen - inc rax - push rdi + call ft_strlen + inc rax ; we add one to the result of strlen for the \0 + push rdi ; we put rdi in r10 for later use mov rdi, rax ; move the result of strlen in rdi - call malloc wrt ..plt - test rax, rax + call malloc wrt ..plt ; + test rax, rax ; test if malloc failled je .end - pop rsi + pop rsi ; we take the value we saved earlier mov rdi, rax ; move the result of malloc into rdi (override strlen result) call ft_strcpy ret .end: - pop r8 + pop rsi ret \ No newline at end of file diff --git a/ft_write.s b/ft_write.s index 02992bb..e59b75a 100644 --- a/ft_write.s +++ b/ft_write.s @@ -2,16 +2,25 @@ global ft_write extern __errno_location ft_write: + cmp rsi, 0 + je .bad_buff mov eax, 0x1 ; put the syscall number of write syscall - test rax, rax + test rax, rax ; test if the syscall failed js .error ret -.error: - mov rdx, rax +.bad_buff: + mov rdx, 22 call __errno_location wrt ..plt - neg rdx mov [rax], rdx mov rax, -1 + ret + +.error: + mov rdx, rax ; move the syscall return value + call __errno_location wrt ..plt + 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