add list remove if and fix valgrind error
This commit is contained in:
@ -9,7 +9,7 @@ ft_list_push_front:
|
||||
|
||||
push rdi
|
||||
push rsi
|
||||
mov rdi, 10
|
||||
mov rdi, 16
|
||||
call malloc wrt ..plt
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
95
srcs/bonus/ft_list_remove_if.s
Normal file
95
srcs/bonus/ft_list_remove_if.s
Normal file
@ -0,0 +1,95 @@
|
||||
global ft_list_remove_if
|
||||
|
||||
section .text
|
||||
|
||||
remove_element:
|
||||
|
||||
call call_free_elem
|
||||
push rax
|
||||
mov rax, [rax + 8]
|
||||
|
||||
test r8, r8
|
||||
jz element_is_first
|
||||
|
||||
mov [r8 + 8], rax
|
||||
pop rax
|
||||
ret
|
||||
|
||||
element_is_first:
|
||||
mov [rdi], rax
|
||||
pop rax
|
||||
ret
|
||||
|
||||
|
||||
call_free_elem:
|
||||
push rdi
|
||||
push rsi
|
||||
push rdx
|
||||
push rcx
|
||||
push rax
|
||||
push r8
|
||||
|
||||
mov rdi, [rax]
|
||||
call rcx
|
||||
|
||||
pop r8
|
||||
pop rax
|
||||
pop rcx
|
||||
pop rdx
|
||||
pop rsi
|
||||
pop rdi
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ft_list_remove_if:
|
||||
test rdi, rdi
|
||||
jz end
|
||||
test rdx, rdx
|
||||
jz end
|
||||
test rcx, rcx
|
||||
jz end
|
||||
|
||||
xor r8, r8
|
||||
|
||||
mov rax, [rdi]
|
||||
loop:
|
||||
test rax, rax
|
||||
jz end
|
||||
push rax
|
||||
|
||||
push rdi
|
||||
push rsi
|
||||
push rdx
|
||||
push rcx
|
||||
push r8
|
||||
|
||||
mov rdi, [rax]
|
||||
call rdx
|
||||
|
||||
test eax, eax
|
||||
pop r8
|
||||
pop rcx
|
||||
pop rdx
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
jz loop_end
|
||||
|
||||
mov rax, [rsp]
|
||||
call remove_element
|
||||
|
||||
loop_end:
|
||||
|
||||
pop rax
|
||||
mov r8, rax
|
||||
mov rax, [rax + 8]
|
||||
jmp loop
|
||||
|
||||
|
||||
|
||||
|
||||
end:
|
||||
ret
|
@ -7,18 +7,16 @@ ft_strcpy:
|
||||
test rsi, rsi
|
||||
jz err
|
||||
push rdi
|
||||
jmp loop_start
|
||||
condition_check:
|
||||
mov al, [rdi]
|
||||
test al, al
|
||||
jz end
|
||||
|
||||
|
||||
loop_start:
|
||||
mov rax, [rsi]
|
||||
mov [rdi], rax
|
||||
mov al, [rsi]
|
||||
mov [rdi],al
|
||||
lea rdi, [rdi + 1]
|
||||
lea rsi, [rsi + 1]
|
||||
jmp condition_check
|
||||
|
||||
test al, al
|
||||
jne loop_start
|
||||
|
||||
end:
|
||||
pop rax
|
||||
|
@ -11,6 +11,7 @@ ft_strdup:
|
||||
|
||||
push rdi ;push to use it for the strcpy
|
||||
call ft_strlen
|
||||
inc rax
|
||||
mov rdi, rax
|
||||
|
||||
call malloc wrt ..plt
|
||||
|
Reference in New Issue
Block a user