Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting floating point exception while trying to use div in assembly

Tags:

x86

assembly

I am trying to run the following code in assembly:

  mov        %si, %ax
  mov        $15, %si
  div        %si
  mov        %eax, %esi

When I make my program, it compiles, but at runtime it gives me a floating point exception. I tried to replace the last line's parameters by %ah and %si.

Briefly, I am trying to divide %esi by 15. I only want an int, and have no need for a double.

Thank you

like image 792
juliensaad Avatar asked Mar 20 '12 18:03

juliensaad


People also ask

What is floating point exception in assembly?

Floating-point exceptions in VFPThe exception is caused if the result of an operation has no mathematical value or cannot be represented. Division by zero. The exception is caused if a divide operation has a zero divisor and a dividend that is not zero, an infinity or a NaN. Overflow.

What causes floating point exception?

A floating point exception is an error that occurs when you try to do something impossible with a floating point number, such as divide by zero. In fluent floating point error can be caused by many factors such as, improper mesh size, defining some property close to zero.

What is floating point in assembly?

In assembly language, there are at least two standard formats for floating-point numbers: short and long. Short floating-point (32 bits): The first bit is the sign bit: 0 for positive and 1 for negative. The next 7 bits are the exponent: -64 to +63, stored as 0 to 127.


1 Answers

The div instruction divides the two-word parameter dx/ax by the operand. If the quotient is too large to fit into a word, it will throw that exception.

Reference: http://siyobik.info.gf/main/reference/instruction/DIV

What do you have in the dx register? Most likely dx/ax divided by 15 does not fit in a 16-bit word.

like image 83
Mysticial Avatar answered Oct 21 '22 05:10

Mysticial