[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Detecting ++/-- overflow
From: |
Wallace White |
Subject: |
[avr-gcc-list] Detecting ++/-- overflow |
Date: |
Tue, 27 May 2003 16:49:09 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3.1) Gecko/20030425 |
Speaking of overflows... what's an efficient way to detect when an
increment or decrement results in an over- or underflow?
Here's what I'm doing now:
signed int counter, overflow;
// Increment counter
if (counter == INT_MAX) {
counter = INT_MIN;
overflow++;
} else {
counter++;
}
But you'd like to do something more like this: (I say this not having
written assembly in a long time)
counter++;
if (bit_is_set(SREG, V)) {
overflow++;
}
I don't know what you can count on the status register being preserved,
though, and I don't really know how multiple byte and signed/unsigned
types are handled. Looks like the INC instruction sets the overflow (V)
flag for signed overflow only...
Thanks,
Wallace
- [avr-gcc-list] Detecting ++/-- overflow,
Wallace White <=