aboutsummaryrefslogtreecommitdiff
path: root/ft_strdup.s
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-23 02:54:37 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-23 02:54:37 +0100
commitb4b6364c2fc4b14a0aaac406891c3880243a9733 (patch)
treee204b7a7cefd18c764cfbf8adb7f1491b689352c /ft_strdup.s
parentc90117251f11e03452ae9808ff8626016c7958a1 (diff)
downloadlibasm-b4b6364c2fc4b14a0aaac406891c3880243a9733.tar.gz
libasm-b4b6364c2fc4b14a0aaac406891c3880243a9733.tar.bz2
libasm-b4b6364c2fc4b14a0aaac406891c3880243a9733.zip
refactored mandatory functions, to respect c calling convention
Diffstat (limited to 'ft_strdup.s')
-rw-r--r--ft_strdup.s21
1 files changed, 10 insertions, 11 deletions
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