[sdiy] Organisation of tasks in synth's main uP
Speth, John
John.Speth at coherent.com
Tue Nov 23 18:10:52 CET 2010
> pro-question time: in assembly, I rely heavily on the overflow bit
> being set to detect wrap-around, e.g. in 8-bit registers. But
> these
> days I program mainly in C and I can't figure out how to access
> that
> overflow bit.
> I have gone so far as to use 7-bit numbers and treat the MSB as an
> overflow, but does anyone know how to read the CPU's overflow bit
> from
> C?
There's no in-built way in C to test for overflow. You, as the designer, must build enough dynamic range into your variables by sizing them adequately to avoid overflow. Or you must build a mechanism into your code that will allow you to test.
There is a simple way to test for overflow that works as long as you don't need all bits in your storage. For example, if you want to detect overflow on adding 12 bits and you are storing in 16 bits, you know you have overflow when bit 12 is high after the addition. Even simpler, testing for a negative number after adding to a C int will give you overflow indication if your usable range is 0 to [(2^N-1)-1].
JJS
The information contained in this communication is confidential and may be legally privileged. It is intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. If you are not the intended recipient you are hereby (a) notified that any disclosure, copying, distribution or taking any action with respect to the content of this information is strictly prohibited and may be unlawful, and (b) kindly requested to inform the sender immediately and delete any copies. Coherent is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt.
More information about the Synth-diy
mailing list