Compare commits

...

2 Commits

Author SHA1 Message Date
8ae1a6e876 use: wrt ..plt instead no-pie 2024-09-03 14:35:27 +02:00
174a587414 add: ft_read 2024-09-03 14:34:52 +02:00
6 changed files with 48 additions and 4 deletions

View File

@ -6,7 +6,7 @@ SRC := $(wildcard $(SRCDIR)/*.asm)
OBJ := $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRC)) OBJ := $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRC))
CC = gcc CC = gcc
CFLAGS = -g -no-pie CFLAGS = -g
AS = nasm AS = nasm
ASFLAGS = -f elf64 -g ASFLAGS = -f elf64 -g

View File

@ -7,4 +7,5 @@ char *ft_strcpy(char *dest, const char *src);
size_t ft_strlen(const char *str); size_t ft_strlen(const char *str);
int ft_strcmp( const char *first, const char *second); int ft_strcmp( const char *first, const char *second);
ssize_t ft_write(int fd, const void *buf, size_t count); ssize_t ft_write(int fd, const void *buf, size_t count);
char *ft_strdup(const char *s); char *ft_strdup(const char *s);
ssize_t ft_read(int fildes, void *buf, size_t nbyte);

25
src/ft_read.asm Normal file
View File

@ -0,0 +1,25 @@
extern __errno_location
section .text
global ft_read
ft_read:
xor rax, rax
syscall
cmp rax, 0
jne syscall_failed
ret
syscall_failed:
neg rax
mov rbx, rax
call __errno_location wrt ..plt
mov [rax], rbx
mov rax, -1
ret

View File

@ -10,8 +10,8 @@ section .text
mov rbx, rdi mov rbx, rdi
mov rdi, rax mov rdi, rax
call malloc call malloc wrt ..plt
cmp rax, 0 cmp rax, 0
je error je error

View File

@ -1,6 +1,23 @@
extern __errno_location
section .text section .text
global ft_write global ft_write
ft_write: ft_write:
mov rax, 1 mov rax, 1
syscall syscall
cmp rax, 0
jne syscall_failed
ret
syscall_failed:
neg rax
mov rbx, rax
call __errno_location wrt ..plt
mov [rax], rbx
mov rax, -1
ret ret

View File

@ -78,4 +78,5 @@ int main()
printf("\n"); printf("\n");
ft_write(1, "bozo\n", 5); ft_write(1, "bozo\n", 5);
printf("%s\n", ft_strdup("sdsfsd"));
} }