; atoi base ; prototype : int ft_atoi_base(char *str, char *base) ;global ft_atoi_base global get_char_index global check_base section .data invalid_chars: db "+- ", 0x0c, 0x0a, 0x0d, 0x09, 0x0b, 0 section .text ; checks if a char is in the invalid_chars get_char_index: xor rax, rax push rsi get_char_index_loop: cmp dil, [rsi] ;is char invalid je get_char_index_found mov al, [rsi] ; is end of string test al, al lea rsi, [rsi + 1] jne get_char_index_loop xor rax, -1 ;not found and at the end pop rsi ret get_char_index_found: pop rax ;return index of the found char sub rsi, rax mov rax, rsi ret ;function that checks if the base is valid ;a valid base does not have any of these char : "+-" or any space defined by isspace(3) and does not have any duplicate char ; returns 0 if base is not valid check_base: xor rax, rax chk_bs_char: mov al, [rdi] ; if rdi is \0, return 0 test al, al je base_ok push rdi ; if current char is in invalid_chars mov dil, [rdi]; lea rsi, [rel invalid_chars] call get_char_index pop rdi cmp rax, -1 ; if not -1, error lea rdi, [rdi + 1] je chk_bs_char xor rax, rax; return 0 ret base_ok: mov rax,1 ret