[Mono-list] Integer division problems

Martin Baulig martin@gnome.org
10 Mar 2002 02:26:52 +0100


"Serge" <serge@wildwestsoftware.com> writes:

> > * x86.brg (DIV, DIV_UN): Clear EDX before performing the division.
> 
> But isn't CDQ (x86_cdq (s->code);) is supposed to take care of it?

According to "The Art of Assembly Programming"

% The cdq instruction sign extends the 32 bit value in eax to 64 bits
% and places the result in edx:eax by copying bit 31 of eax throughout
% bits 0..31 of edx.

This means that if EAX is 0x80000000 (the unsigned value 2147483648),
the CDQ instruction puts 0xffffffff into EDX - and we're performing an
unsigned division (which raises an int 0 since the result doesn't fit
into EAX anymore).

-- 
Martin Baulig
martin@gnome.org