I am testing a printconsole function and i want to print "." for 10 times but instead i get an infinite loop. Can someone tell me whats wrong with my code
.386
.model flat, stdcall ;32 bit memory model
option casemap :none ;case sensitive
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
.data
CStdIn dd 0
CStdOut dd 0
COutStr db "."
ClnpStr db 255 dup (0),0
.code
start:
call OpenConsole
mov eax,0
loopness:
inc eax
call PrintConsole
cmp eax,10
je returnness
jmp loopness
returnness:
call CloseConsole
ret
OpenConsole:
call AllocConsole
push STD_INPUT_HANDLE
call GetStdHandle
mov CStdIn, eax
push STD_OUTPUT_HANDLE
call GetStdHandle
mov CStdOut, eax
ret
CloseConsole:
call FreeConsole
mov CStdIn, 0
mov CStdOut, 0
ret
PrintConsole:
push 0
push 0
push sizeof COutStr
push offset COutStr
push CStdOut
call WriteConsole
ret
end start
The API functions, like the MASM32 procedures, do not preserve EAX, ECX, or EDX. Possible solutions are:
Store ther loop counter in one of the registers that are preserved: EBX, ESI, or EDI.
Store the loop counter in a variable.
Store the loop counter on the stack before the call and recover it after the call returns.
Thanks, i switched it to ebx and it works. But the problem is, the program activates so fast that i cannot tell if it is actually 10 of "." drawn. What are some possible methods to slow down every "." drawn. GetTickCount or something?
invoke Sleep,1000
? :bg
Thanks everyone, it all works. But just a question. MichaelW, what's wrong with using ecx? I thought that register is what loop counters use anyway?
I don't know any of the reasoning behind the decision to do so, but (E)CX has always been used as a scratch register in the Microsoft high-level languages. The LOOP instruction is hard-coded to use ECX, but these days most programmers tend to avoid using LOOP because it's relatively slow.