-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_list_remove_if.s
73 lines (66 loc) · 2.02 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
global ft_list_remove_if
extern free
section .text
ft_list_remove_if: ; rdi = t_list **begin, rsi = void *data_ref, rdx = int (*cmp)(), rcx = void (*free_fct)(void *)
enter 0, 0 ; r8 = t_list *prev, r9 = t_list *elem, r10 = t_list *next
cmp rdx, 0x0
je ft_list_remove_if_ret
cmp rcx, 0x0
je ft_list_remove_if_ret
mov r9, QWORD [rdi] ; elem = *begin
mov QWORD r8, 0 ; prev = NULL
ft_list_remove_if_loop:
cmp r9, 0x0 ; if next = NULL
je ft_list_remove_if_ret
push r8
push r9
push r10
push rdi
push rsi
push rcx
push rdx
mov rdi, QWORD [r9]
call [rsp] ; call int (*cmp)() => rdi = elem->data, rsi = data_ref
pop rdx
pop rcx
pop rsi
pop rdi
pop r10
pop r9
pop r8
cmp rax, 0 ; if return of int (*cmp)() == 0
je ft_list_remove_if_equal
mov QWORD r8, r9 ; prev = elem
mov QWORD r9, [r9+8] ; elem = elem->next
jmp ft_list_remove_if_loop
ft_list_remove_if_equal: ; if int (*cmp)() == 0
mov r10, [r9+8] ; next = elem->next
push r8
push r10
push rdi
push rsi
push rdx
push r9
push rcx
mov rdi, QWORD [r9]
call [rsp] ; call void (*free_fct)(void *) => rdi = elem->data
mov rdi, QWORD [rsp+8]
call free ; call free => rdi = elem->data (rsp+8 == r9)
pop rcx
pop r9
pop rdx
pop rsi
pop rdi
pop r10
pop r8
mov r9, r10 ; elem = next
cmp r8, 0 ; if prev == NULL
je ft_list_remove_if_prev_null
mov QWORD [r8+8], r9 ; prev->next = elem
jmp ft_list_remove_if_loop
ft_list_remove_if_prev_null:
mov QWORD [rdi], r9 ; *begin = elem
jmp ft_list_remove_if_loop
ft_list_remove_if_ret:
leave
ret