fix atoi and list_remove_if
This commit is contained in:
@ -9,26 +9,33 @@ whitespaces: db " ", 0x0c, 0x0a, 0x0d, 0x09, 0x0b, 0
|
||||
|
||||
section .text
|
||||
|
||||
; checks if a char is in the invalid_chars
|
||||
; get index of char in string or returns -1 if not found
|
||||
; char in dil
|
||||
; str in rsi
|
||||
get_char_index:
|
||||
xor rax, rax
|
||||
push rsi
|
||||
|
||||
get_char_index_loop:
|
||||
push rsi ; keep start index in stack
|
||||
|
||||
test dil, dil
|
||||
je .error
|
||||
|
||||
.get_char_index_loop:
|
||||
cmp dil, [rsi] ;is char invalid
|
||||
jz get_char_index_found
|
||||
jz .get_char_index_found
|
||||
|
||||
mov al, [rsi] ; is end of string
|
||||
test al, al
|
||||
lea rsi, [rsi + 1]
|
||||
jne get_char_index_loop
|
||||
jne .get_char_index_loop
|
||||
|
||||
.error
|
||||
mov rax, -1 ;not found and at the end
|
||||
pop rsi
|
||||
ret
|
||||
|
||||
get_char_index_found:
|
||||
pop rax ;return index of the found char
|
||||
.get_char_index_found:
|
||||
pop rax ;return index of the found char (compare to top of stack)
|
||||
sub rsi, rax
|
||||
mov rax, rsi
|
||||
ret
|
||||
@ -113,9 +120,9 @@ base_ok:
|
||||
ft_atoi_base:
|
||||
xor rax, rax ;check if there is a null pointer in rdi or rsi
|
||||
test rdi, rdi
|
||||
jz final_number
|
||||
jz return
|
||||
test rsi, rsi
|
||||
jz final_number
|
||||
jz return
|
||||
|
||||
push rdi ; is base valid
|
||||
push rsi
|
||||
@ -126,10 +133,8 @@ ft_atoi_base:
|
||||
|
||||
test rax, rax
|
||||
jne whitespace_skip ; if 0 , base is not valid
|
||||
xor rax, rax
|
||||
ret
|
||||
|
||||
|
||||
whitespace_skip_inc:
|
||||
lea rdi, [rdi + 1]
|
||||
whitespace_skip:
|
||||
@ -160,6 +165,7 @@ plus_minus:
|
||||
cmp al, '+'
|
||||
jz plus_minus_inc
|
||||
|
||||
push rdx ; keep invert sign setting in stack
|
||||
|
||||
|
||||
push rdi
|
||||
@ -169,12 +175,10 @@ plus_minus:
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
mov rbx, rax
|
||||
mov rbx, rax ; keep the length of the base in rbx
|
||||
|
||||
xor rax, rax
|
||||
|
||||
push rdx
|
||||
|
||||
number_loop:
|
||||
mov dl, [rdi]
|
||||
test dl, dl
|
||||
@ -191,7 +195,7 @@ number_loop:
|
||||
mov rdx, rax ; save return value in rdx
|
||||
pop rax
|
||||
|
||||
cmp rdx, -1
|
||||
cmp rdx, -1 ; if the char is not in the base, return the number
|
||||
jz final_number
|
||||
|
||||
push rdx ; imul sets rdx to 0
|
||||
@ -211,4 +215,5 @@ final_number:
|
||||
|
||||
neg_final_number:
|
||||
neg rax
|
||||
return:
|
||||
ret
|
||||
|
Reference in New Issue
Block a user