52 lines
429 B
NASM
52 lines
429 B
NASM
|
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
|
||
|
|