62 lines
872 B
ArmAsm
62 lines
872 B
ArmAsm
global ft_list_remove_if
|
|
extern free
|
|
|
|
ft_list_remove_if:
|
|
push rsp ; push callee saved registers
|
|
push rbx
|
|
push r12
|
|
push r13
|
|
push r14
|
|
push r15
|
|
push rsi
|
|
mov r14, rdx ; save cmp func
|
|
mov r15, rcx ; save free func
|
|
mov r13, rdi ; save begin_list
|
|
mov rbx, 0 ; prev = null
|
|
mov r12, [r13] ; curr = *begin_list
|
|
|
|
.loop:
|
|
cmp r12, 0
|
|
je .done
|
|
mov rdi, [r12]
|
|
pop rsi
|
|
push rsi
|
|
call r14
|
|
cmp rax, 0
|
|
jne .next
|
|
cmp rbx, 0
|
|
je .first_elem
|
|
mov rdi, [r12]
|
|
call r15
|
|
mov rax, [r12 + 8]
|
|
mov [rbx + 8], rax
|
|
mov rdi, r12
|
|
call free WRT ..plt
|
|
mov r12, [rbx + 8]
|
|
jmp .loop
|
|
|
|
.first_elem:
|
|
mov rdi, [r12]
|
|
call r15
|
|
mov rax, [r12 + 8]
|
|
mov [r13], rax
|
|
mov rdi, r12
|
|
call free WRT ..plt
|
|
mov r12, [r13]
|
|
jmp .loop
|
|
|
|
.next:
|
|
mov rbx, r12 ; prev = curr
|
|
mov r12, [r12 + 8] ; curr = curr->next
|
|
jmp .loop
|
|
|
|
.done:
|
|
pop rsi
|
|
pop r15
|
|
pop r14
|
|
pop r13
|
|
pop r12
|
|
pop rbx
|
|
pop rsp
|
|
ret
|