I've just started learning MASM and I wrote a sample code that should run a simple loop.
mov eax, 1
x: add eax,1
print str$(eax),13,10
cmp eax, 4
jne x
inkey
exit
So, I expected this tiny program to print 2,3,4. What I'm getting, however, is an infinite loop somehow and keeps printing 3. Any clues why it's not working as I thought?
eax
is a volatile register, meaning its value is not required to be saved across function/macro calls. You need to saveeax
before theprint
macro and restore it afterwards:Or just use a non-volatile register which value is required to be saved by the callee (esi, edi, ebx)