feat: ft_strcpy
This commit is contained in:
parent
c1a848d05b
commit
ff8d51b1c4
6
Makefile
6
Makefile
|
@ -1,6 +1,8 @@
|
||||||
NAME = libasm
|
NAME = libasm
|
||||||
|
|
||||||
SRC = ft_strlen.s
|
SRC = \
|
||||||
|
ft_strlen.s \
|
||||||
|
ft_strcpy.s \
|
||||||
|
|
||||||
OBJ = $(SRC:.s=.o)
|
OBJ = $(SRC:.s=.o)
|
||||||
|
|
||||||
|
@ -13,7 +15,7 @@ $(NAME): $(OBJ)
|
||||||
ar rcs libasm.a $(OBJ)
|
ar rcs libasm.a $(OBJ)
|
||||||
|
|
||||||
test: $(NAME)
|
test: $(NAME)
|
||||||
gcc -Wall -Werror -Wextra main.c -L. -lasm -o libasm_unit_tests
|
gcc -Wall -Werror -Wextra -g main.c -L. -lasm -o libasm_unit_tests
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJ)
|
rm $(OBJ)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
global ft_strcpy
|
||||||
|
|
||||||
|
ft_strcpy:
|
||||||
|
xor rax, rax
|
||||||
|
.loop:
|
||||||
|
cmp byte [rsi + rax], 0
|
||||||
|
je .done
|
||||||
|
mov rdx, [rsi + rax]
|
||||||
|
mov [rdi + rax], rdx
|
||||||
|
inc rax
|
||||||
|
jmp .loop
|
||||||
|
.done:
|
||||||
|
mov rax, rdi
|
||||||
|
ret
|
3
libasm.h
3
libasm.h
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
ssize_t ft_strlen(const char *);
|
size_t ft_strlen(const char *);
|
||||||
|
char *ft_strcpy(char *, const char *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
11
main.c
11
main.c
|
@ -1,6 +1,17 @@
|
||||||
#include "libasm.h"
|
#include "libasm.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printf("%ld\n", ft_strlen("c'est moi la chaine de 36 caracteres"));
|
printf("%ld\n", ft_strlen("c'est moi la chaine de 36 caracteres"));
|
||||||
|
|
||||||
|
char *str;
|
||||||
|
str = (char *)malloc(150 * sizeof(char));
|
||||||
|
str = "Salut c'est moi la zone mdr\0";
|
||||||
|
char *dst;
|
||||||
|
dst = (char *)malloc(50 * sizeof(char));
|
||||||
|
char *test = ft_strcpy(dst, str);
|
||||||
|
printf("%s\n", str);
|
||||||
|
printf("%s\n", dst);
|
||||||
|
printf("%s\n", test);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue