diff --git a/atoi.asm b/atoi.asm index e9db137..7364e7b 100644 --- a/atoi.asm +++ b/atoi.asm @@ -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 - - cmp r8, rdi - je _exitloop2asd12 - jmp _loop2asd12 -_exitloop2asd12: +; pop rax - 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 diff --git a/atoi_legacy.asm b/atoi_legacy.asm new file mode 100644 index 0000000..e9db137 --- /dev/null +++ b/atoi_legacy.asm @@ -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 +