libasm/ft_strdup.s

24 lines
432 B
ArmAsm

global ft_strdup
extern malloc
extern ft_strlen
extern ft_strcpy
ft_strdup:
push rdi ; save string to available register
call ft_strlen
mov rdi, rax
inc rdi ; null terminated
call malloc WRT ..plt
cmp rax, 0 ; if malloc failed
jz .error
mov rdi, rax ; store malloc adress to dest
pop rsi ; restore string address to source
call ft_strcpy
jmp .done
.error:
pop rsi ; restore stack bc we skipped line #15
.done:
ret