Jump to content
gbgb

Division By Zero - What Happens In This Case?

Recommended Posts

Is there an expected behavior for a division by zero? Will the PC jump to a certain location?

If not - is there a way that I can catch this exception so that I can handle this situation?

Share this post


Link to post
Share on other sites

Most PIC processors do not have hardware divide logic so division is done in software. It is up to the compiler to decide to implement exception handling or not. Since code space is usually a premium, I would expect that BoostC does nothing but give you a bad answer. For most tiny embedded processors, you will have to check your inputs and handle divide by zero yourself so that you can handle it the way that is best for your application.

Share this post


Link to post
Share on other sites

If the PC jumped to a certain location it would tell you in the manual.

 

It is your responsibility to check the value of the divisor if there is a possibility of it being zero.

 

As trossin said division is performed in software. If a divide by zero happens then the result would probably be the maximum value for the data type.

 

If you are using the floating point library then the float_exception_flags would inform you that a divide by zero occurred.

It is your responsibility to check these flags. See manual.

 

If you write a small program and run the simulator you can test for yourself what happens.

 

I hope this sheds some light for you.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×