Compare commits
14 Commits
a05124885e
...
master
Author | SHA1 | Date | |
---|---|---|---|
66cc5c87d4 | |||
0b4d562ef9 | |||
42b7aab1ae | |||
e3b2eb0852 | |||
ebf0b0e442 | |||
3effb7caf5 | |||
27f25d2cea | |||
fdc1923211 | |||
cbed6c468f | |||
eadf7cde62 | |||
b1a86b85fe | |||
49283f4227 | |||
8ae1a6e876 | |||
174a587414 |
4
Makefile
4
Makefile
@ -6,7 +6,7 @@ SRC := $(wildcard $(SRCDIR)/*.asm)
|
||||
OBJ := $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRC))
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -g -no-pie
|
||||
CFLAGS = -g
|
||||
|
||||
AS = nasm
|
||||
ASFLAGS = -f elf64 -g
|
||||
@ -24,7 +24,7 @@ all : $(NAME)
|
||||
|
||||
test : $(NAME)
|
||||
$(CC) $(CFLAGS) test/test.c $(BUILDDIR)/$(NAME) -o $(BUILDDIR)/test
|
||||
$(BUILDDIR)/test
|
||||
valgrind --leak-check=full $(BUILDDIR)/test
|
||||
|
||||
clean :
|
||||
rm -rf $(OBJDIR)
|
||||
|
@ -8,3 +8,4 @@ size_t ft_strlen(const char *str);
|
||||
int ft_strcmp( const char *first, const char *second);
|
||||
ssize_t ft_write(int fd, const void *buf, size_t count);
|
||||
char *ft_strdup(const char *s);
|
||||
ssize_t ft_read(int fildes, void *buf, size_t nbyte);
|
30
src/ft_read.s
Normal file
30
src/ft_read.s
Normal file
@ -0,0 +1,30 @@
|
||||
extern __errno_location
|
||||
|
||||
section .text
|
||||
global ft_read
|
||||
ft_read:
|
||||
|
||||
xor rax, rax
|
||||
|
||||
syscall
|
||||
|
||||
cmp rax, 0
|
||||
jne syscall_failed
|
||||
|
||||
ret
|
||||
|
||||
syscall_failed:
|
||||
|
||||
push rbx
|
||||
|
||||
neg rax
|
||||
mov rbx, rax
|
||||
|
||||
call __errno_location wrt ..plt
|
||||
|
||||
mov [rax], rbx
|
||||
mov rax, -1
|
||||
|
||||
pop rbx
|
||||
|
||||
ret
|
@ -2,6 +2,8 @@ section .text
|
||||
global ft_strcmp
|
||||
|
||||
ft_strcmp:
|
||||
push rbx
|
||||
|
||||
xor rcx, rcx
|
||||
|
||||
loop:
|
||||
@ -20,4 +22,7 @@ section .text
|
||||
out:
|
||||
sub bl, dl
|
||||
movsx rax, bl
|
||||
|
||||
pop rbx
|
||||
|
||||
ret
|
@ -5,12 +5,15 @@ extern ft_strcpy
|
||||
section .text
|
||||
global ft_strdup
|
||||
ft_strdup:
|
||||
push rbx
|
||||
|
||||
call ft_strlen
|
||||
|
||||
mov rbx, rdi
|
||||
mov rdi, rax
|
||||
add rdi, 1
|
||||
|
||||
call malloc
|
||||
call malloc wrt ..plt
|
||||
|
||||
cmp rax, 0
|
||||
je error
|
||||
@ -20,8 +23,13 @@ section .text
|
||||
|
||||
call ft_strcpy
|
||||
|
||||
pop rbx
|
||||
|
||||
ret
|
||||
|
||||
error:
|
||||
xor rax, rax
|
||||
|
||||
pop rbx
|
||||
|
||||
ret
|
@ -6,7 +6,9 @@ section .text
|
||||
loop:
|
||||
cmp BYTE [rdi + rcx], 0
|
||||
je out
|
||||
|
||||
inc rcx
|
||||
|
||||
jmp loop
|
||||
out:
|
||||
mov rax, rcx
|
@ -1,6 +0,0 @@
|
||||
section .text
|
||||
global ft_write
|
||||
ft_write:
|
||||
mov rax, 1
|
||||
syscall
|
||||
ret
|
28
src/ft_write.s
Normal file
28
src/ft_write.s
Normal file
@ -0,0 +1,28 @@
|
||||
extern __errno_location
|
||||
|
||||
section .text
|
||||
global ft_write
|
||||
ft_write:
|
||||
mov rax, 1
|
||||
|
||||
syscall
|
||||
|
||||
cmp rax, 0
|
||||
jne syscall_failed
|
||||
|
||||
ret
|
||||
|
||||
syscall_failed:
|
||||
|
||||
push rbx
|
||||
|
||||
neg rax
|
||||
mov rbx, rax
|
||||
|
||||
call __errno_location wrt ..plt
|
||||
mov [rax], rbx
|
||||
mov rax, -1
|
||||
|
||||
pop rbx
|
||||
|
||||
ret
|
34
test/test.c
34
test/test.c
@ -1,6 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include "../include/libasm.h"
|
||||
#include "../headers/libasm.h"
|
||||
#include "string.h"
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
void test_size_t(size_t expected_value, size_t value)
|
||||
{
|
||||
@ -60,6 +63,30 @@ void multiple_test_strcpy(char *(*own_func)(char *, const char *), const char *
|
||||
|
||||
}
|
||||
|
||||
void multiple_test_atoi_base(char *(*own_func)(char *, const char *), const char * const *values[2])
|
||||
{
|
||||
char tmp[4096];
|
||||
|
||||
for (size_t i = 0; values[i] != NULL; i++)
|
||||
{
|
||||
printf("test: %s", values[i]);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void multiple_test_strdup(const char * const *values)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
for (size_t i = 0; values[i] != NULL; i++)
|
||||
{
|
||||
tmp = ft_strdup(values[i]);
|
||||
test_str(tmp, values[i]);
|
||||
free(tmp);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("STRLEN\n");
|
||||
@ -77,5 +104,8 @@ int main()
|
||||
multiple_test_strcpy(ft_strcpy, strcpy_tests);
|
||||
printf("\n");
|
||||
|
||||
ft_write(1, "bozo\n", 5);
|
||||
printf("STRDUP\n");
|
||||
const char *strdup_tests[] = {"yo", "", "bonjour", "co\0fgf", NULL};
|
||||
multiple_test_strdup(strdup_tests);
|
||||
printf("\n");
|
||||
}
|
Reference in New Issue
Block a user