You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
f6/7 idiv r/m8 -- Unexpected results where #DE should have been raised #3
There are 9 tests where I would expect a divsion error to be signalled, but instead it behaves as if bit 14 of the numerator was flipped, but only in cases where the "new" quotient ends up being 80h.
These tests are (and only those, all other IDIV tests behave as I'd expect):
I.e. AX = 9c71h = -25487 and CL = 47h = 71. 16-bit quotient = -359 => Should raise #DE.
Instead the result is AH = f1h = -15, AL = 80h = -128, as if the numerator was -128*71-15 = -9103 = dc71h = 9c71h^4000h
This pseudo-code makes the tests pass (surely the logic is not like this, but I don't have a good theory for what trigger this behavior):
if SRC = 0:
#DE
q16 := AX / SRC
if q16 > 7fh:
#DE
if q16 < 80h:
q16 := (AX ^ 4000h) / SRC
if q16 <> 80h:
#DE
AH := (AX ^ 4000h) mod SRC
else:
AH := AX mod SRC
AL := q16 & ffh
Activity
tremalrik commentedon Jan 26, 2026
IDIVfailing to generate the #DE exception in some overflow cases is a known CPU erratum of some Intel 386 and 486 processors - see e.g. 272874-001 Intel 386DX specification update specification change 002 on page 14, or Grzegorz Mazur's old 386/486 bug page at https://web.archive.org/web/19970403004354/http://grafi.ii.pw.edu.pl/gbm/x86/3486bugs.html .