-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_list_remove_if_bonus.s
executable file
·81 lines (75 loc) · 1.56 KB
/
ft_list_remove_if_bonus.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
; void ft_list_remove_if(rdi = t_list **begin_list, rsi = void *data_ref, rdx = int (*cmp)());
section .text
global _ft_list_remove_if
extern _free
_ft_list_remove_if:
test rdi, rdi ; check if agrs == NULL
jz .ret
test rdx, rdx
jz .ret
push r10
push r11
.loop_begin:
mov r10, [rdi] ; r10 = *begin_list
test r10, r10 ; check if *begin_list == NULL
jz .loop_mid
push rdi ; save args
push rsi
mov rdi, [r10] ; rdi = *begin_list->data
call rdx ; *cmp(rdi=(*begin_list)->data, rsi=data_ref)
pop rsi
pop rdi
test eax, eax ; check cmp ret
jnz .loop_mid
mov r10, [rdi]
mov r11, [r10+8] ; r11 = *begin_list->next
mov [rdi], r11 ; *begin_list = (*begin_list)->next
push rdi
push rsi
push rdx
push r10
push r11
mov rdi, r10 ; rdi = *begin_list
call _free ; free(rdi=*begin_list)
pop r11
pop r10
pop rdx
pop rsi
pop rdi
jmp .loop_begin
.loop_mid:
test r10, r10 ; check if r10 == NULL
jz .ret
mov r11, [r10+8] ; r11 = r10->next
test r11, r11 ; check if tmp->next == NULL
jz .ret
push rdi
push rsi
mov rdi, [r11] ; rdi = tmp->next->data
call rdx ; *cmp(rdi=(*being_list)->data, rsi=data_ref)
pop rsi
pop rdi
test eax, eax ; check cmp ret
jnz .next
push rdi
push rsi
push rdx
push r10
push r11
mov rdi, r11 ; rdi = tmp->next
mov r11, [r11+8] ; r11 = tmp->next->next
mov [r10+8], r11 ; r10->next = tmp->next->next
call _free ; free(rdi=tmp->next)
pop r11
pop r10
pop rdx
pop rsi
pop rdi
jmp .loop_mid
.next:
mov r10, r11 ; r10 = tmp->next
jmp .loop_mid
.ret:
pop r11
pop r10
ret