-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_list_remove_if.s
120 lines (115 loc) · 2.07 KB
/
ft_list_remove_if.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
; rdi = t_list **begin, rsi = *data_ref, rdx = int (*cmp)(data, data_ref), rcx = void (*free_fct)(data)
section .note.GNU-stack
section .data
section .bss
section .text
global ft_list_remove_if
extern free
ft_list_remove_if:
push rbp
push rbx
push r12
mov r12, [rdi]
xor rbx, rbx
cmp rdi, 0
jz .quit
cmp rdx, 0
jz .quit
cmp rcx, 0
jz .quit
jmp .comp
.apply_free:
mov r8, [rdi]
mov rbp, [r8 + 8] ; tmp = (*begin)->next
push rsi
push rdx
push rcx
push rdi
mov rdx, [rdi]
mov rdi, [rdx]
call rcx ; (*free_fct)((*begin)->data)
pop rdi
push rdi
mov rdx, [rdi]
lea rdi, [rdx]
call free wrt ..plt ; free(*begin)
pop rdi
pop rcx
pop rdx
pop rsi
mov [rdi], rbp ; *begin = tmp
cmp rbx, 0 ; previous == NULL
jnz .prev
mov r12, rbp ; first == tmp
jmp .comp
.prev:
mov [rbx + 8], rbp ; previous.next = tmp
jmp .comp
.comp_null:
xor rdi, rsi
lea rax, [rdi]
jmp .cmp_last
.next:
mov rbx, [rdi]
mov r8, [rbx + 8] ; tmp = (*begin)->next
mov [rdi], r8 ; *begin = tmp
.comp:
cmp qword [rdi], 0 ; *begin == NULL
jz .quit
push rdi
push rsi ; data_ref already in rsi
push rdx
push rcx
mov r8, [rdi]
mov rdi, [r8] ; (*begin)->data in rdi
cmp rdi, 0 ; (*begin)->data == NULL
jz .comp_null
call rdx ; (*cmp)((*begin)->data, data_ref)
.cmp_last:
pop rcx
pop rdx
pop rsi
pop rdi
cmp rax, 0
jz .apply_free
jmp .next
.quit:
mov [rdi], r12
pop r12
pop rbx
pop rbp
ret
; void my_free(t_list *ptr, void (*free_fct)(void *))
; {
; if (free_fct)
; free_fct(ptr->data);
; free(ptr);
; }
; void ft_list_remove_if(t_list **begin_list, void *data_ref,
; int (*cmp)(), void (*free_fct)(void *))
; {
; t_list *ptr;
; t_list *tmp;
; ptr = *begin_list;
; tmp = NULL;
; while (ptr)
; {
; if (cmp(ptr->data, data_ref) == 0)
; {
; if (tmp)
; tmp->next = ptr->next;
; else
; *begin_list = ptr->next;
; my_free(ptr, free_fct);
; if (tmp)
; ptr = tmp->next;
; else
; ptr = *begin_list;
; }
; else
; {
; tmp = ptr;
; ptr = ptr->next;
; }
; }
; }