Valhalla Legends Archive

Programming => General Programming => Assembly Language (any cpu) => Topic started by: iago on May 14, 2004, 01:59 PM

Title: I don't quite understand this..
Post by: iago on May 14, 2004, 01:59 PM
.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


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
Title: Re:I don't quite understand this..
Post by: Arta on May 14, 2004, 02:22 PM
Yeah, div modifies edx. I think it stores the remainder? Something like that.
Title: Re:I don't quite understand this..
Post by: Maddox on May 14, 2004, 03:49 PM
div edx is equivalent to
temp = edx;
eax = eax / temp;
edx = eax % temp;

This piece of code is probably doing some aligning.
Title: Re:I don't quite understand this..
Post by: Adron on May 14, 2004, 06:14 PM
Quote from: Maddox on May 14, 2004, 03:49 PM
div edx is equivalent to
temp = edx;
eax = eax / temp;
edx = eax % temp;

This piece of code is probably doing some aligning.

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.
Title: Re:I don't quite understand this..
Post by: iago on May 14, 2004, 07:51 PM
ooh, you're right, I didn't even notice that div!  Silly me!  Thanks :)