-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strcpy.s
More file actions
32 lines (27 loc) · 1.38 KB
/
ft_strcpy.s
File metadata and controls
32 lines (27 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
; **************************************************************************** ;
; ;
; ::: :::::::: ;
; ft_strcpy.s :+: :+: :+: ;
; +:+ +:+ +:+ ;
; By: lrocca <marvin@42.fr> +;+ +:+ +;+ ;
; +;+;+;+;+;+ +;+ ;
; Created: 2021/04/03 15:14:46 by lrocca ;+; ;+; ;
; Updated: 2021/04/03 15:14:48 by lrocca ;;; ;;;;;;;;.fr ;
; ;
; **************************************************************************** ;
section .text
global _ft_strcpy
; char *ft_strcpy(char *rdi, const char *rsi);
_ft_strcpy:
xor rcx, rcx ; index starts from 0
_loop:
cmp byte [rsi + rcx], 0 ; compare *(str + index)
jz _ret ; src == 0, go to return
mov al, byte [rsi + rcx] ; move src (2nd arg) char to register
mov byte [rdi + rcx], al ; copy from register to dst (1st arg)
inc rcx ; increment index
jmp _loop ; repeat if not zero
_ret:
mov byte [rdi + rcx], 0 ; null terminate dst
mov rax, rdi ; return dst
ret