TestingtoPreventOverflowFault

gbradley

Lifetime Supporting Member
Join Date
Apr 2002
Location
Corona, Ca.
Posts
1,637
Is there a way to test two numbers before you do the ADD to make sure that the sum is below 32767?
If I add two integers together and the result is greater than 32767 I believe the processor faults.

I was thinking of dividing each individual source by two, and then adding them up and then testing the Sum of those to see if it is less than 16384, if so, then go ahead do the add.
attachment.php


OverFlow.jpg Trouble.jpg
 
gbradley said:
. . .If I add two integers together and the result is greater than 32767 I believe the processor faults.

Not exactly. The processor sets the overflow bit immediately afterward, but does not fault right away. At the end of the scan, if the overflow bit is still set, then it faults.

The best way to trap this is to examine the overflow bit right after any potentially offending math, and if it is set, then OTL your own internal bit, and OTU the overflow bit.

Use your own internal bit to perform whatever action is required (if any).

That is a whole lot simpler than what you had proposed.

Paul
 
The overflow bit result from an ADD as you describe does not immediately fault the processor. In your next rung you can test for the overflow bit. if it is on then do whatever you need to do to cope with the situation. Then perform an Unlatch of the overflow bit. Everything is fine!

If you were to do noting with a set overflow bit and the scan reaches the end THEN it becomes a processor fault.

[Darn Paul's flying fingers]
 
So you are saying go ahead and add the numbers, let the chips fall where they may, and then if if S:0/1 is set, then do whatever I need to do to remedy the situation and then unlatch S:0/1.
 
Does the processor you have support floating point? If so change the dest. of your ADD instruction to a floating point register.
 
Does the processor you have support floating point?
It's SLC5/02, so Float is not an option.
I fixed the offending problem and will add some code to trap for the overflow with a pop up screen to let me know if it happens.
Thanks
 
Back
Top Bottom