flat assembler
Message board for the users of flat assembler.
Index
> Main > A loop question |
Author |
|
goldenspider 07 Oct 2011, 06:06
Aha , Because EAX will be change. So,
xor eax, eax mylabel: inc eax push eax invoke WriteConsole,[outhandle],"Hello",5,numwritten,0 invoke WriteConsole,[outhandle],endline,1,numwritten,0 pop eax cmp eax,10 jne mylabel |
|||
07 Oct 2011, 06:06 |
|
Madis731 07 Oct 2011, 06:08
invoke and usually every other code uses eax as return value therefore its trashed every time.
You have two options: 1) use a different register (esi, edi, ebx) that should be preserved 2) after inc eax use push eax and just before cmp eax,10 use pop eax The second method is the safest and you can even use eax as a scratchpad between the push/pop. There are other methods, like using a memory area to handle the counting. Use your imagination. |
|||
07 Oct 2011, 06:08 |
|
ManOfSteel 07 Oct 2011, 06:09
You should push eax after incrementing it and pop it back before comparing it to 10. You can't trust the API to save registers.
EDIT: geez there's an invasion in progress. |
|||
07 Oct 2011, 06:09 |
|
bolzano_1989 07 Oct 2011, 07:12
Thank you ManOfSteel, Madis731, goldenspider for your clear explanation and your fix .
|
|||
07 Oct 2011, 07:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.