The output from printf
is returned in eax
which contains the number of characters printed: 3 in your case (the digit, CR, and LF). Since that is less than 10, you loop up, add 1 (which makes it 4), print that, and repeat.
What you need to do is store eax (push eax
) before setting up the printf
call, then restore it (pop eax
) after printf
returns like:
loop1:
inc eax
push eax ; store eax
push eax
push msg2
call [printf]
add esp,8 ; clean the stack from the printf call
pop eax ; restore eax
cmp eax,10
jb loop1
Or use a different register such as ebx
for your loop variable.