change labels from global to local in functions, align function calls in stack
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user