add: strdup
This commit is contained in:
27
src/ft_strdup.asm
Normal file
27
src/ft_strdup.asm
Normal file
@ -0,0 +1,27 @@
|
||||
extern ft_strlen
|
||||
extern malloc
|
||||
extern ft_strcpy
|
||||
|
||||
section .text
|
||||
global ft_strdup
|
||||
ft_strdup:
|
||||
call ft_strlen
|
||||
|
||||
mov rbx, rdi
|
||||
mov rdi, rax
|
||||
|
||||
call malloc
|
||||
|
||||
cmp rax, 0
|
||||
je error
|
||||
|
||||
mov rdi, rax
|
||||
mov rsi, rbx
|
||||
|
||||
call ft_strcpy
|
||||
|
||||
ret
|
||||
|
||||
error:
|
||||
xor rax, rax
|
||||
ret
|
Reference in New Issue
Block a user