1

I keep getting 'Program received signal SIGFPE, Arithmetic exception' when dividing in x86 Assembly. It's confusing because the answer should be smaller than a 64 bit answer if I divide by 10....

mov $0x82b40000, $eax
mov $0x21c3677c, $edx
mov $10000000, %ebx
div %ebx
1

2 Answers 2

3

The arithmetic exception is "Integer overflow", from the #DE hardware divide exception! Which is normal or expected, because your result is bigger than 32-bit number.

Remember: the quotient of 64 bit / 32-bit division is only a 32 bit register (EAX). The EDX output is the remainder, not high half of the quotient. The operand-size of div %ebx is 32-bit; only the dividend is 64-bit.

Intel's datasheet has a useful table:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Okay, thanks. I googled the error and the explanations were a little hard to understand; this is the first time I'm working with assembly on a real machine.
3

You'll need to do this division similar to long hand division by hand. Put the dividend in another pair of registers or memory. Then clear edx and load eax with the high order dividend. Then divide edx:eax by the 32 bit divisor, and store eax (quotient) back into high order dividend. Next load eax with low order dividend (leaving edx alone), and divide by the 32 bit divisor again. Store eax back into low order dividend. After this, high and low order dividend = dividend/divisor (a 64 bit quotient), and edx = dividend % divisor (32 bit remainder).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.