remade atoi it no longer nukes your string

This commit is contained in:
zombie maniac 2021-10-04 16:34:02 -04:00
parent bd059e097f
commit 048a43083a
2 changed files with 114 additions and 63 deletions

View file

@ -6,83 +6,46 @@ section .text
libz_atoi:
mov r8, rdi
xor r9, r9
_loopasd23:
mov r9b, [r8]
cmp r9, 0 ;check and see if we have reached the end of the string
jz _exitloopasd12
sub r9, 48
mov [r8], r9b
inc r8
jmp _loopasd23
_exitloopasd12:
; mov r11, rdi ;saveing it for later
push rdi
call libz_strlen
mov r8, rax
mov r11, rax
add r8, rdi
dec r8
push r8
inc r8
mov r9, rax
pop rdi
xor r10, r10
mov rcx, 1
_loop2asd12:
dec r8
mov al, [r8]
add r9, rdi
dec r9
_loop:
xor rax, rax
mov al, [r9]
; push rax
sub rax, 48
mul rcx
mov [r8], al
add r10, rax
; pop rax
mov rax, rcx
mov r10, 10
mul r10
cmp r9, rdi
je _end
dec r9
; push rax
mov rax, 10
mul rcx
mov rcx, rax
; pop rax
cmp r8, rdi
je _exitloop2asd12
jmp _loop2asd12
_exitloop2asd12:
mov r8, rdi
mov r9, rdi
inc r9
_loop3asd12:
mov r11b, [r9]
mov r10b, [r8]
cmp r11, 0
jz _endasdasd23123
add r11, r10
mov [r9], r11b
mov [r8], r10b
jmp _loop
inc r8
inc r9
jmp _loop3asd12
_endasdasd23123:
pop r8
mov rax, [r8]
_end:
mov rax, r10
ret

88
atoi_legacy.asm Normal file
View file

@ -0,0 +1,88 @@
extern libz_strlen
global libz_atoi
section .text
libz_atoi:
mov r8, rdi
xor r9, r9
_loopasd23:
mov r9b, [r8]
cmp r9, 0 ;check and see if we have reached the end of the string
jz _exitloopasd12
sub r9, 48
mov [r8], r9b
inc r8
jmp _loopasd23
_exitloopasd12:
call libz_strlen
mov r8, rax
mov r11, rax
add r8, rdi
dec r8
push r8
inc r8
mov rcx, 1
_loop2asd12:
dec r8
mov al, [r8]
mul rcx
mov [r8], al
mov rax, rcx
mov r10, 10
mul r10
mov rcx, rax
cmp r8, rdi
je _exitloop2asd12
jmp _loop2asd12
_exitloop2asd12:
mov r8, rdi
mov r9, rdi
inc r9
_loop3asd12:
mov r11b, [r9]
mov r10b, [r8]
cmp r11, 0
jz _endasdasd23123
add r11, r10
mov [r9], r11b
mov [r8], r10b
inc r8
inc r9
jmp _loop3asd12
_endasdasd23123:
pop r8
mov rax, [r8]
ret