I'm not sure how anybody else handles their loops, but this
is what I've just figured out. (After surfing the forum a bit and
then putting together my final style)
This is the loop in my programs context:
This is the loop by its self, quick example:
Does anybody have a better way to do this?
I noticed that when there was an error (before I fixed it), and the
loop never finished, it used 99 percent of my cpu according to
windows 2000.. and lagged everything a bit.
Is there a way to avoid loop-lag like that?
Thanks, !
is what I've just figured out. (After surfing the forum a bit and
then putting together my final style)
This is the loop in my programs context:
invoke FindFirstFile, ADDR file, ADDR FindFileData
mov hSearch, eax
xor ecx, ecx
.while ecx != 1
PrintString FindFileData.cFileName ; Debug function to
; print the name of
; the file found..
invoke FindNextFile, hSearch, ADDR FindFileData
.if eax == 0 ; if there are no more files,
mov ecx, 1 ; or there was an error, end
.endif ; the loop
.endw
This is the loop by its self, quick example:
xor ecx, ecx
.while ecx != 1
mov ecx, 1 ; setup loop exit, you could use inc and an .if for a counter
.endw
Does anybody have a better way to do this?
I noticed that when there was an error (before I fixed it), and the
loop never finished, it used 99 percent of my cpu according to
windows 2000.. and lagged everything a bit.
Is there a way to avoid loop-lag like that?
Thanks, !
matthew,
Be careful, eax, ecx, edx may modify when certain function call.
If your code never end, maybe ecx modified during function call.
In your case, use ".break" instead "mov ecx, 1", like below
code:--------------------------------------------------------------------------------
invoke FindFirstFile, ADDR file, ADDR FindFileData
mov hSearch, eax
xor ecx, ecx
.while ecx != 1
PrintString FindFileData.cFileName ; Debug function to
; print the name of
; the file found..
invoke FindNextFile, hSearch, ADDR FindFileData
.break .if eax == 0
;.if eax == 0 ; if there are no more files,
;mov ecx, 1 ; or there was an error, end
;.endif ; the loop
.endw
Be careful, eax, ecx, edx may modify when certain function call.
If your code never end, maybe ecx modified during function call.
In your case, use ".break" instead "mov ecx, 1", like below
code:--------------------------------------------------------------------------------
invoke FindFirstFile, ADDR file, ADDR FindFileData
mov hSearch, eax
xor ecx, ecx
.while ecx != 1
PrintString FindFileData.cFileName ; Debug function to
; print the name of
; the file found..
invoke FindNextFile, hSearch, ADDR FindFileData
.break .if eax == 0
;.if eax == 0 ; if there are no more files,
;mov ecx, 1 ; or there was an error, end
;.endif ; the loop
.endw
If I use .break like in the example you gave, I wouldnt
really need to use a while statement to begin with...
Is there any statement i can use to just loop it?
Something like
.do
invoke FindNextFile, hSearch, ADDR FindFileData
.break .if eax == 0
.end
?
really need to use a while statement to begin with...
Is there any statement i can use to just loop it?
Something like
.do
invoke FindNextFile, hSearch, ADDR FindFileData
.break .if eax == 0
.end
?
OK, I've figured it out...
Final code is like so:
In my example it produces:
Thanks for showing me .break :)
I was originally intending to use compares and jumps...
Final code is like so:
invoke FindFirstFile, ADDR file, ADDR FindFileData
mov hSearch, eax
.repeat
PrintString FindFileData.cFileName
invoke FindNextFile, hSearch, ADDR FindFileData
.break .if eax == 0
.until 0
In my example it produces:
Program Execution Begun (ListFiles.asm, 43)
----------------------------------------
FindFileData.cFileName = file_1.jpg (ListFiles.asm, 50)
FindFileData.cFileName = file_2.jpg (ListFiles.asm, 50)
FindFileData.cFileName = file_3.jpg (ListFiles.asm, 50)
Thanks for showing me .break :)
I was originally intending to use compares and jumps...
matthew I attached an example to your previous thread of a routine I used lately :)