libasm/ft_strdup.s

24 lines
432 B
ArmAsm
Raw Permalink Normal View History

2024-02-26 04:47:24 +00:00
global ft_strdup
extern malloc
extern ft_strlen
extern ft_strcpy
ft_strdup:
2024-03-11 16:30:24 +00:00
push rdi ; save string to available register
2024-02-26 04:47:24 +00:00
call ft_strlen
mov rdi, rax
2024-03-11 16:30:24 +00:00
inc rdi ; null terminated
2024-03-10 19:07:02 +00:00
call malloc WRT ..plt
2024-03-11 16:30:24 +00:00
cmp rax, 0 ; if malloc failed
jz .error
mov rdi, rax ; store malloc adress to dest
pop rsi ; restore string address to source
2024-02-26 04:47:24 +00:00
call ft_strcpy
2024-03-11 16:30:24 +00:00
jmp .done
.error:
pop rsi ; restore stack bc we skipped line #15
2024-02-26 04:47:24 +00:00
.done:
ret