From 0e0434fcbc2c0bfcba48f53352d29490e3b4fe79 Mon Sep 17 00:00:00 2001 From: lohhiiccc Date: Thu, 18 Jun 2026 17:30:14 +0200 Subject: [PATCH] feat: ft_list_push_front --- Makefile | 3 ++- src/ft_list_push_front.asm | 55 ++++++++++++++++++++++++++++++++++++++ src/libasm.h | 7 +++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/ft_list_push_front.asm diff --git a/Makefile b/Makefile index 39603c0..b01981b 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,8 @@ SRCS=$(SRC_DIR)/ft_strlen.asm \ $(SRC_DIR)/ft_memcpy.asm \ $(SRC_DIR)/ft_isspace.asm \ $(SRC_DIR)/ft_bzero.asm \ - $(SRC_DIR)/ft_atoibase.asm + $(SRC_DIR)/ft_atoibase.asm \ + $(SRC_DIR)/ft_list_push_front.asm \ OBJS=$(patsubst $(SRC_DIR)/%.asm,$(OBJ_DIR)/%.o,$(SRCS)) DEPS=$(OBJS:.o=.d) diff --git a/src/ft_list_push_front.asm b/src/ft_list_push_front.asm new file mode 100644 index 0000000..67469d0 --- /dev/null +++ b/src/ft_list_push_front.asm @@ -0,0 +1,55 @@ +global ft_list_push_front +extern malloc +extern ft_memcpy + +%define NODE_SIZE 16 + +section .text +;#include +;#include "ft_list.h" +; +;void ft_list_push_front(t_list **begin_list, void *data) +;{ +; t_list *new_elem; +; +; if (!begin_list) +; return ; +; new_elem = (t_list *)malloc(sizeof(t_list)); +; if (!new_elem) +; return ; +; new_elem->data = data; +; new_elem->next = *begin_list; +; *begin_list = new_elem; +;} + +; rdi: t_list **begin_list +; rsi: void *data +ft_list_push_front: + ; if NULL == begin_list return + test rdi, rdi + je .done + + push rdi + push rsi + + ; malloc 16 + mov rdi, NODE_SIZE + call malloc wrt ..plt + + pop rsi + pop rdi + + ; if NULL == rax return + test rax, rax + je .done + + ; new_elem->data = data; + ; new_elem->next = *begin_list; + ; *begin_list = new_elem; + mov [rax], rsi + mov rdx, [rdi] + mov [rax + 8], rdx + mov [rdi], rax + +.done: + ret diff --git a/src/libasm.h b/src/libasm.h index c85ced9..97e841b 100644 --- a/src/libasm.h +++ b/src/libasm.h @@ -6,6 +6,12 @@ extern "C" { #endif +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + size_t ft_strlen(const char *str); char *ft_strcpy(char *dest, const char *src); int ft_strcmp (const char *p1, const char *p2); @@ -15,6 +21,7 @@ ssize_t ft_read(int fd, void *buf, size_t count); void *ft_memcpy(void *dest, const void *src, size_t n); void ft_bzero(void *s, size_t n); int ft_atoibase(char *str, char *base); +void ft_list_push_front(t_list **begin_list, void *data); #ifdef __cplusplus }