As you see! Pretty clever. these compilers. eh?
Here's another one (also stolen from a compiler). You know how to convert ascii text to integer, right? Multiply "result so far" by ten, and add in the digit (after converting ascii character to number)...
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
;--------
(gawd, I hope that's more readable when it unwraps!)
lea "looks" like a "memory function", but it doesn't touch memory at all - it's really an "arithmetic function". Can't do arbitrary arithmetic with it, of course, but anything that has the form of a valid effective address can be calculated with lea.
Might be interesting to experiment and see just *how* clever the compiler is at this!
Best,
Frank