Valhalla Legends Forums Archive | Assembly Language (any cpu) | I don't quite understand this..

AuthorMessageTime
iago
[code].text:15006DD1 xor edx, edx
.text:15006DD3 mov eax, esi
.text:15006DD5 div ecx
.text:15006DD7 push edi
.text:15006DD8 mov edi, esi
.text:15006DDA test edx, edx
.text:15006DDC jz short loc_15006DE4
.text:15006DDE sub ecx, edx
[/code]

Can edx possibly be non-zero there? If not, why would the compiler even allow this? Note that there aren't any cross references to the middle of that
May 14, 2004, 6:59 PM
Arta
Yeah, div modifies edx. I think it stores the remainder? Something like that.
May 14, 2004, 7:22 PM
Maddox
div edx is equivalent to
temp = edx;
eax = eax / temp;
edx = eax % temp;

This piece of code is probably doing some aligning.
May 14, 2004, 8:49 PM
Adron
[quote author=Maddox link=board=7;threadid=6802;start=0#msg60128 date=1084567790]
div edx is equivalent to
temp = edx;
eax = eax / temp;
edx = eax % temp;

This piece of code is probably doing some aligning.
[/quote]

div edx would be
__int64 temp = (edx<<32) + eax;
eax = temp / edx;
edx = temp % edx;

Makes more sense to use ecx for dividing, since edx is part of the number you're dividing by edx too.
May 14, 2004, 11:14 PM
iago
ooh, you're right, I didn't even notice that div! Silly me! Thanks :)
May 15, 2004, 12:51 AM

Search