flat assembler
Message board for the users of flat assembler.
Index
> Windows > Loop - problem :D |
Author |
|
r22 15 Jul 2005, 17:17
TWO POSSIBLE ISSUES
1)The API function your calling changes the value of ECX. 2)You are only setting CX to 10 the upper half of ECX could still have a value in it (in which case the loop would seem to never end). FIX Code: mov ecx,10 abc: push ecx invoke MessageBox, 0, 0, 0, 0 pop ecx loop abc OR replace ecx with a register that isn't changed by API function like ebp, ebx, esi, edi. |
|||
15 Jul 2005, 17:17 |
|
T&K(r) 15 Jul 2005, 17:24
I Tested this and i have the same problem even if i changeing registers (toECX) or pushing and poping.
The best will be if you write something like that : Code: mov cx, 10 abc: invoke MessageBox, 0, 0, 0, 0 dec cx jcxz abc_end jmp abc abc_end: This is working - i checked it. _________________ my GG ( Polish Instant Messager ) number is 8734187 Gdy widzisz kolejke - wstąp do niej - co ci szkodzi |
|||
15 Jul 2005, 17:24 |
|
dieboy 15 Jul 2005, 17:52
r22 wrote:
_________________ ... |
|||
15 Jul 2005, 17:52 |
|
r22 15 Jul 2005, 22:16
--------------
mov ecx,10 .abc: push ecx push 0 push 0 push 0 push 0 call [MessageBox] pop ecx loop .abc ;dec ECX; JNZ .abc ------------------- Works on my box (winxp sp2). Maybe because your label isn't a local one (shouldnt affect it but who knows). All the LOOP opcode does is DEC ecx JNZ labal In most cases the above runs faster. When you call an API like MessageBox, it doesn't save the states of EAX, ECX or EDX so you have to do it manually or use a register that IS preserved over API calls like EBX,EBP,ESI,orEDI. |
|||
15 Jul 2005, 22:16 |
|
Reverend 15 Jul 2005, 23:18
T&K(r) wrote: The best will be if you write something like that : Why do you use 'jcxz' opcode? After 'dec ecx' if ecx was 1 a ZF flag is signed (as ecx will have value 0), so you can use just 'jz'. And in this case even, you can omit defining another label 'abc_end', because you can use 'jnz' and jump back. Even though the loop is bad, because MessageBox changes ecx, and you do not preserve it anyway. I'll suggest this: Code: mov ecx, 10 abc: push ecx invoke MessageBox, 0, 0, 0, 0 pop ecx dec ecx jnz abc P.S: 'dec ecx\ jz XXXXXX' does the same as 'loop XXXXXX'. Loop is smaller in bytes but also slower |
|||
15 Jul 2005, 23:18 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.