From b4b6364c2fc4b14a0aaac406891c3880243a9733 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 23 Nov 2019 02:54:37 +0100 Subject: refactored mandatory functions, to respect c calling convention --- ft_strdup.s | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'ft_strdup.s') diff --git a/ft_strdup.s b/ft_strdup.s index fa28326..8ff46b5 100644 --- a/ft_strdup.s +++ b/ft_strdup.s @@ -16,20 +16,19 @@ extern _malloc global _ft_strdup -; char *ft_strdup(const char*); +; char *ft_strdup(const char *str); _ft_strdup: - push rbp - mov rbp, rsp - mov rbx, rdi - mov rax, rbx - call _ft_strlen - inc rax - mov rdi, rax + push rdi ; save rdi because it will be overwrite for malloc + + call _ft_strlen ; rdi is still == str + inc rax ; len++ for '\0' + + mov rdi, rax ; size to malloc call _malloc - mov rdi, rax - mov rsi, rbx + + pop rsi ; original str as src + mov rdi, rax ; allocated as dest call _ft_strcpy - pop rbp ret -- cgit