I've started learning assembly and I have some problems with a program. I'm trying to write a program that would print some text x-times (x would be inputed by me), but I always get an infinite loop, because it seems that the counter value doesn't get updated in the register in each iteration, therefore it never reaches the "x".

My code

extern printf
extern scanf
global main

section .data

text db "Random text",10,0
input db "%d",10,0
number dd 0

section .text


push dword number
push dword input
call scanf
add esp,8
mov eax,[number]
mov ecx,1


push dword text
call printf
add esp,4
inc ecx
cmp ecx,eax
jle .loop


Any help would be much appriciated.

I'd be willing to bet that printf changes the eax register... Have you looked into that?

You're probably right, because i tried to increment the value in it twice in a row outside the loop, withouth using printf before. I only used it after and the value was indeed incremented twice like it was supposed to be.

Also, eax getting messed up isn't the only problem in my code, ecx doesn't get incremented either.
EDIT: well actually it does get, but it resets back after the code jumps back to the start of the loop

Managed to solve it. Printf was indeed messing with the values in the register, so a simple pushad before the function call and a popad after solved it.