i (hopefully) made atoi return 0 if its not a number

@quantum fix
i should probably make it more complient with the spec
This commit is contained in:
zombie maniac 2021-11-21 03:21:48 -05:00
parent 048a43083a
commit bba6630833
3 changed files with 58 additions and 2 deletions

View file

@ -25,6 +25,10 @@ _loop:
xor rax, rax xor rax, rax
mov al, [r9] mov al, [r9]
cmp rax, 48
jb _nan
cmp rax, 57 ;if its not a number then return 0 then exit
ja _nan
; push rax ; push rax
sub rax, 48 sub rax, 48
@ -43,7 +47,8 @@ _loop:
jmp _loop jmp _loop
_nan:
xor r10 r10
_end: _end:
mov rax, r10 mov rax, r10

51
atoi_legacy2.asm Normal file
View file

@ -0,0 +1,51 @@
extern libz_strlen
global libz_atoi
section .text
libz_atoi:
; mov r11, rdi ;saveing it for later
push rdi
call libz_strlen
mov r9, rax
pop rdi
xor r10, r10
mov rcx, 1
add r9, rdi
dec r9
_loop:
xor rax, rax
mov al, [r9]
; push rax
sub rax, 48
mul rcx
add r10, rax
; pop rax
cmp r9, rdi
je _end
dec r9
; push rax
mov rax, 10
mul rcx
mov rcx, rax
; pop rax
jmp _loop
_end:
mov rax, r10
ret

View file

@ -7,7 +7,7 @@ extern libz_atoi
section .data section .data
text2 db "asdasdASDd",0 text2 db "asdasdASDd",0
text db "asdasdasd",0 text db "asdasdasd",0
text3 dq "65",0 text3 dq "5",0
textstore dq 0,0 textstore dq 0,0
stoer db "0",0 stoer db "0",0
differ db "they differ",0 differ db "they differ",0