diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-11-23 02:54:37 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-11-23 02:54:37 +0100 |
| commit | b4b6364c2fc4b14a0aaac406891c3880243a9733 (patch) | |
| tree | e204b7a7cefd18c764cfbf8adb7f1491b689352c /ft_strdup.s | |
| parent | c90117251f11e03452ae9808ff8626016c7958a1 (diff) | |
| download | libasm-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.s | 21 |
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 |
