global to_int section .text ; ; angle translation from string to integer ; [ebp+8] is pointer to string ; eax=-1 if digit is not 0-9 ; else eax=number ; to_int: push ebp mov ebp, esp sub esp, 8 ; local variables push esi ; save esi mov dword [ebp-4], 0 ; init number mov dword [ebp-8], 10 ; init const mov esi, [ebp+8] ; buffer cld .lp: lodsb cmp al, 0 je .store cmp al, '0' jl .error cmp al, '9' jg .error sub al, '0' xor ecx, ecx xchg al, cl mov eax, [ebp-4] mul dword [ebp-8] add eax, ecx mov [ebp-4], eax jmp .lp .error: mov eax, -1 jmp .quit .store: mov eax, [ebp-4] .quit: pop esi mov esp, ebp pop ebp ret