Why this program does not work correctly:
It should return something like this:
string-1
string-2
string-3
string-4
string-5
:stupid:
;-- ------------------------------------------------------
.386
.model flat,stdcall
option casemap:none
include c:\masm32\include\windows.inc
include c:\masm32\include\kernel32.inc
includelib c:\masm32\lib\kernel32.lib
.data
fstr db "string-%d",13,10,0
.data?
hOutput dd ?
buf db 11 dup(?)
n dd ?
.code
start:
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hOutput, eax
mov ecx,5
lbl:
invoke wsprintf, addr buf, addr fstr, ecx
invoke WriteConsole, hOutput, addr buf, 11, addr n, NULL
loop lbl
invoke ExitProcess, 0
end start
;--------------------------------------------------------
It should return something like this:
string-1
string-2
string-3
string-4
string-5
:stupid:
ECX gets modified by the WriteConsole call. So push/pop it before/after calling the function.
And you should replace the "mov ecx, 5" with
xor ecx, ecx
inc ecx
and do a "inc ecx" after the wsprintf call _before_ you push it :)
Oh, and dont use the "loop" instruction :/
And you should replace the "mov ecx, 5" with
xor ecx, ecx
inc ecx
and do a "inc ecx" after the wsprintf call _before_ you push it :)
Oh, and dont use the "loop" instruction :/
Oh, and dont use the "loop" instruction :/
The "loop" instruction is OK to use unless it would be part of a time-critical section of code and it would be imperative to get the fastest execution.
In code such as this thread's example, a few more nanosecs wouldn't be noticeable.
OTOH, the "loop" instruction MUST always be used whenever you would aim for the smallest code size possible.
Raymond
Bazik,
Could you add "Download a debugger" to your signature ?:rolleyes:
Could you add "Download a debugger" to your signature ?:rolleyes:
wsprintf changes ecx too.
Bazik,
Could you add "Download a debugger" to your signature ?:rolleyes:
Yes,nice remark from Axial.
Maybe, Bazik can add this one to his sig:"Beta testers,red alarm! New product from M$"
Regards,
Vortex