Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,339 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,787 people online right now. Registration is fast and FREE... Join Now!




Why do I get Floating point exception when I divide?

 
Reply to this topicStart new topic

Why do I get Floating point exception when I divide?, using idiv x86 nasm

no2pencil
27 Aug, 2008 - 12:12 AM
Post #1

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,460



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
CODE

_div: ; use division
  push ebp       ; bring in the arguments.
  mov ebp, esp
  mov eax, [ebp+8]; Argument 1
  mov edx, [ebp+12]; Argument 2
  xor edx, edx; clear out register edx
  mov edx, ebx; Place ebx *argument 2* into ebx
  idiv ebx; Divide EDX:EAX by EBX
  pop eax; Return the quotient
  ret


No matter what arguments I give, I get the dreaded floating point exception error. I can't find a proper explanation w/Google as to why! Any ideas?
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Why Do I Get Floating Point Exception When I Divide?
27 Aug, 2008 - 12:41 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,460



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
I'm not sure if this is correct, but this is what I did to fix it :

CODE

_div:
  push ebp
  mov ebp, esp
  mov eax, [ebp+8] ; low
  mov edx, 0           ; high
  idiv dword [ebp+12] ; divide edx:eax by ebp+12 (2nd argument)
  mov [ebp+12],eax ; Store the remainder back into ebp
  pop ebp                 ; return the quotient
  ret

User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Why Do I Get Floating Point Exception When I Divide?
27 Aug, 2008 - 12:50 AM
Post #3

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,025



Thanked: 35 times
Dream Kudos: 125
My Contributions
You copied your argument 2 in edx and then cleared it in next statement using XOR. I think you wanted to copy your second argument in ebx instead of edx, right?

CODE

mov edx, [ebp+12]; Argument 2    You copied it to edx and not ebx
  xor edx, edx; clear out register edx
  mov edx, ebx; Place ebx *argument 2* into ebx    but you never had argument 2 in ebx!!!


May be it was just a typo. Correct it and see whether it works.
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Why Do I Get Floating Point Exception When I Divide?
27 Aug, 2008 - 12:57 AM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,460



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(AmitTheInfinity @ 27 Aug, 2008 - 04:50 AM) *

Correct it and see whether it works.

Yeah tongue.gif

Now how can I return the remainder? Shouldn't it be in register edx?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 08:12AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month