bozo
This commit is contained in:
2
Makefile
2
Makefile
@@ -6,7 +6,7 @@
|
||||
# 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 #
|
||||
# Updated: 2024/03/27 17:45:37 by vvaas ### ########.fr #
|
||||
# #
|
||||
#******************************************************************************#
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
14
ft_strdup.s
14
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
|
||||
17
ft_write.s
17
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
|
||||
Reference in New Issue
Block a user