32 lines
437 B
ArmAsm
32 lines
437 B
ArmAsm
extern malloc
|
|
global ft_strdup
|
|
extern ft_strcpy
|
|
extern ft_strlen
|
|
extern __errno_location
|
|
section .text
|
|
|
|
ft_strdup:
|
|
test rdi, rdi ; test if arg is NULL
|
|
jz err
|
|
|
|
push rdi ;push to use it for the strcpy
|
|
call ft_strlen
|
|
mov rdi, rax
|
|
|
|
call malloc wrt ..plt
|
|
test rax, rax
|
|
jz malloc_failed
|
|
mov rdi, rax
|
|
pop rsi
|
|
call ft_strcpy
|
|
ret
|
|
|
|
malloc_failed:
|
|
call __errno_location wrt ..plt
|
|
mov dword [rax], 12
|
|
pop rax
|
|
|
|
err:
|
|
xor rax, rax
|
|
ret
|