Asm in release?
Hi, i am learning asm a bit and the first thing i dit was replacing a for loop with this:
WORD z2=g_h*g_d*g_w;
WORD index2=0;
_asm {
push cx
mov cx,z2
_drawvertexloop:
mov index2,cx
};
vertices[index2].DrawVertex();
_asm {
mov cx,index2
loop _drawvertexloop
pop cx
};
The for version works fine in both debug and release mode but the asm version causes access violation. Is there any reason for that?
I use VC++6.0, no optimisations.
edit: i added the push/pop cx lines to see if that fixed it but it didn't.
2nd edit: i know this is probably very dumb and n00b-like code but it's the first i ever did in asm, and it already runs faster in debug mode so it's not totally crap i guess.
[edited by - Tree Penguin on June 10, 2004 4:11:26 PM]
Well, that fixes the error but no matter where i put it only one point is drawn, where should i put it (in case i for some reason forgot a place) and what else could it be? (i guess i should put it before mov index2,cx).
EDIT: i also don't see why that would help because the cx register is automatically decreased right?
[edited by - Tree Penguin on June 10, 2004 4:34:19 PM]
EDIT: i also don't see why that would help because the cx register is automatically decreased right?
[edited by - Tree Penguin on June 10, 2004 4:34:19 PM]
Use ecx.
Windows is 32-bit, use a 32-bit reg. Using 16 bit reg gets a prefix byte that will increase the size of you program.
And use DWORD.
push cx unbalances the stack, Windows likes it 4 byte aligned.
Windows is 32-bit, use a 32-bit reg. Using 16 bit reg gets a prefix byte that will increase the size of you program.
And use DWORD.
push cx unbalances the stack, Windows likes it 4 byte aligned.
Also, the ''loop'' instruction while in 32-bit mode works with ecx and since the upper 16-bits of ecx are undefined here, this could end up being one huge loop. Clearly that would likely GPF if ECX = &hFFFF0002 for example (3 vertices but upper bits all set by previous code)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement