change labels from global to local in functions, align function calls in stack

This commit is contained in:
2025-08-06 20:10:05 +02:00
parent 2a65c14032
commit caa21a3fb0
11 changed files with 119 additions and 108 deletions

View File

@ -1,5 +1,6 @@
extern malloc
global ft_strdup
extern malloc
extern ft_strcpy
extern ft_strlen
extern __errno_location
@ -7,7 +8,7 @@ section .text
ft_strdup:
test rdi, rdi ; test if arg is NULL
jz err
jz .err
push rdi ;push to use it for the strcpy
call ft_strlen
@ -16,17 +17,21 @@ ft_strdup:
call malloc wrt ..plt
test rax, rax
jz malloc_failed
jz .malloc_failed
mov rdi, rax
pop rsi
sub rsp, 8
call ft_strcpy
add rsp, 8
ret
malloc_failed:
.malloc_failed:
sub rsp, 8
call __errno_location wrt ..plt
add rsp, 8
mov dword [rax], 12
pop rax
err:
.err:
xor rax, rax
ret