IET
Decrease font size
Increase font size
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 Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 21 July 2010 10:33 AM
User is offline View Users Profile Print this message



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
User is offline View Users Profile Print this message



ectophile

Posts: 552
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
User is offline View Users Profile Print this message


Avatar for lowson_i.
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
<snip> that for overflow, the difference is the sign <snip>
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 MIET

Do or do not, there is no try!

Edited: 13 August 2010 at 08:48 AM by lowson_i
Statistics

See Also:



FuseTalk Standard Edition v3.2 - © 1999-2014 FuseTalk Inc. All rights reserved.