Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIV/IDIV should trap on all overflow, not just divide by zero #13

Open
neldredge opened this issue Mar 9, 2023 · 2 comments
Open

DIV/IDIV should trap on all overflow, not just divide by zero #13

neldredge opened this issue Mar 9, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@neldredge
Copy link

If IDIV would produce a quotient of 0x8000 (word) or 0x80 (byte), the real 8086 traps (INT 0, divide overflow). 8086-Emulator yields 0x8000 and continues. (Note this behavior changed between 8086 and 80386, not sure what the 80186/80286 did.)

@neldredge neldredge changed the title IDIV should trap when producing most negative result DIV/IDIV should trap on all overflow, not just divide by zero Mar 9, 2023
@neldredge
Copy link
Author

In fact the emulator only traps on div/idiv when the divisor is actually zero. It should trap whenever the mathematical result does not fit in the destination register. For instance

mov ax, 0xffff
mov dx, 0xffff
mov bx, 1
div bx

should trap with INT 0.

@YJDoc2
Copy link
Owner

YJDoc2 commented Mar 9, 2023

Yes, this is correct. When implementing, apparently I read the spec incorrectly, and thought it was specifically for 0

@YJDoc2 YJDoc2 added the bug Something isn't working label Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants