feat: ft_list_push_front
This commit is contained in:
parent
e9bae396ca
commit
0e0434fcbc
3 changed files with 64 additions and 1 deletions
3
Makefile
3
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)
|
||||
|
|
|
|||
55
src/ft_list_push_front.asm
Normal file
55
src/ft_list_push_front.asm
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
global ft_list_push_front
|
||||
extern malloc
|
||||
extern ft_memcpy
|
||||
|
||||
%define NODE_SIZE 16
|
||||
|
||||
section .text
|
||||
;#include <stdlib.h>
|
||||
;#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
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue