IET
 Topic Title: Overflow and carry of binary numbers? Topic Summary: Created On: 21 July 2010 10:33 AM Status: Read Only Linear : Threading : Single : Branch
Search Topic
Topic Tools
 View similar topics Print this topic.
 21 July 2010 10:33 AM Jasper12 Posts: 3 Joined: 30 June 2010 Can I say that for overflow, the difference is the sign while for carry,the difference is in the magnitude. Otherwise, do you mind clarify with examples if possible. Thanks a lot. 21 July 2010 01:19 PM ectophile Posts: 596 Joined: 17 September 2001 I think you need to elaborate on the question. Are you adding or multiplying, or something else? Are the numbers signed or unsigned? If they are signed, is it 1's complement or 2's complement? ------------------------- S P Barker BSc PhD MIET 13 August 2010 08:23 AM lowson_i Posts: 130 Joined: 23 June 2008 If it's pure microprocessor accumulator operation then I believe (been 20 years) an overflow is where the accumulator has "overflowed" the size. The uP overflow flag would be set. This would be where an 8bit accumulator has gone from 11111111 to 00000000 as it would in this case: 11111111 00000001+ -------------- 00000000 overflow flag set You would not get an overflow on the following: 00000001 00000001+ -------------- 00000010 overflow flag not set In the case of a logical operation the overflow flag is not set. 11111111 10000001 and -------------- 10000001 overflow flag not set Thus when using "unsigned" values you care about the overflow. In the case of signed and unsigned values the uP knows nothing about them. The string of bits in the accumulator can be used to represent different series of values though . Taking the first function, this may be representing (-1 - - 1) or (255 + 1). With "signed" values you need to check for a different condition that the uP doesn't support directly. The sign is the Most Significant Bit of the accumulator Take: 01111111 00000001 + -------------- 10000000 overflow flag not set This is effectively saying that +127 + 1 = -128. Hmm overflow not set no error? But the MSB altered state! ERROR! 11111111 00000001+ -------------- 00000000 overflow flag set Overflow error? No because the MSB altered state!!! So for every "signed" arithmetic operation for need to check the MSB to see if it flips without an overflow, and flips with an overflow. As you "care" about the state of the overflow for both "unsigned" and "signed" values, you cannot say that for overflow, the difference is the sign Originally posted by: Jasper12 However it is perfectly true to say that on the overflow flag being set and when using the accumulator to represent signed values this may not be an error condition. ------------------------- Ian Lowson MIETDo or do not, there is no try! Edited: 13 August 2010 at 08:48 AM by lowson_i
 IET » Information technology » Overflow and carry of binary numbers? Topic Tools
Statistics