I'd adjust the numbering on that slightly - you want to multiply "result so far" by ten before adding "this digit". You might want to make sure you've *got* a valid digit, too - those pesky users'll type any old thing!
There are a number of ways to do it. This is based roughly on "the way C does it" - that is, no check for overflow, and it just quits if it encounters an invalid (decimal) digit. Trashes ecx and edx. You might want to "improve" that behavior. I thought the use of the "lea"s to accomplish the "multiply-by-ten" and the "subtract 48" in one go was clever (stolen from a C compiler!). (don't hand that in as homework unless you can explain how it works!)
atoi:
mov edx, [esp + 4] ; pointer to string
xor eax, eax ; clear "result"
.top:
movzx ecx, byte [edx]
inc edx
cmp ecx, byte '0'
jb .done
cmp ecx, byte '9'
ja .done
; we have a valid character - multiply
; result-so-far by 10, subtract '0'
; from the character to convert it to
; a number, and add it to result.
lea eax, [eax + eax * 4]
lea eax, [eax * 2 + ecx - 48]
jmp short .top
.done
ret
The forum software is gonna clobber the formatting on that! "jmp short.top" is gonna become "jmp short.top" (which won't assemble), I betcha! Watch out for it!
If you wish to accept negative numbers, you're going to have to watch out for a "-", and deal with it. (routine above should be named atou, perhaps) If you wish to accept hex (a "programmer's calulator"), you'll have to watch for upper and lower case a..f. (might as well throw in binary) If you wish to accept/display exponents (a "scientific calulator")... watch for "e" or "E"... If you wish to accept/display floating-point numbers... use scanf and printf :) Seriously, floats can be done but they're a PITA!!! The Unix "dc" caculator is arbitrary precision (will do numbers bigger than will fit in a register)!
Start simple - there's endless room for improvement.
Best,
Frank