| Author | beginning argument ( Replies received: 2 ) |
| Spkt |
Posted 23-04-2006 at 16:16   |

Registered on : 04-23-2006
From 0
Messages : 9
OFF-Line
|
I'm trying to program ST52F513K3 for my graduation project and came across to this problem:
I have a signed "variable" that can either have underflows or overflows. I understand that since isoverflow() and isunderflow()functions aren't available in st5 series, I need to check the carry and sign flags in input register 38. I tried the following code:
variable=a-b; //Now I will check for over-underflow:
if(IsBitSet(_inpReg_38,0))
variable=127;
else if(IsBitSet(_inpReg_38,1))
variable=-128;
variable is a signed byte. a and b are bytes.
However, this code doesn't work. As far as I understand, the carry flag is never set in overflows, and the sign flag is set if the operation "a-b" has a negative result, that's not necessarily an underflow.
How do I tell if there is an under/overflow correctly? Can someone help me out?
|
|
|
Profile
Quote
|
| Nino |
Posted 26-04-2006 at 17:08   |


Registered on : 10-01-2002
Messages : 33
OFF-Line
|
Please, check in the attached file if it is good for you.
| Attachments : | subtraction.htm | | | |
|
|
|
Profile
Quote
|
| Spkt |
Posted 30-04-2006 at 22:23   |

Registered on : 04-23-2006
From 0
Messages : 9
OFF-Line
|
Thanks Nino, your suggestion seems to work fine for me.
|
|
|
Profile
Quote
|