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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With