Overflow Detection

Discussion in 'Homework Help' started by vincent19-mas, Dec 20, 2013.

  1. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    Dear friends,

    I read about overflow detection. But one thing that I do not understand is that what is the purpose of classifying the arithmetic operation to either overflow exist or not ?

    Please have a look at the image attached :)

    If overflow means that the output is invalid ?

    For example, +5 + 3 = +8 (expected)

    but in actual it gave us 1000, which is -8 in 2s complement. So means the operation is not valid ?

    Thanks !
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    In a 2's complement representation an overflow is the result of arithmetic operations exceeding the upper or lower bounds of the representation range. In your example a 4-bit quantity can represent any number in the range [-8,...,+7]. Any result outside that range is an overflow. If you look at the datasheet for a processor with an overflow condition code, you will see a Boolean equation for overflow. IIRC it involves the sign of the result and the signs of the operands.
     
  3. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    So does my example shown is overflow case ? why is that so ?

    Thanks !
     
  4. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,395
    497
    You don't have an example.

    Do you have unsigned 4 bit number?
    Do you have signed 4 bit number where 3 bits represent the number and fourth bit represent sign?
     
  5. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    You have to pick a representation. The 4-bit quantities are either unsigned or signed 2's complement or they could be signed 1s complement or any other variety of representation. Once we know what is the intended representation we can tell what "overflow" means.

    In your first example you have an "expectation" that you can represent +8 as the sum of +3 and +5. This is nonsense since +8 is not a representable number in 2's complement signed notation.
     
  6. WBahn

    Moderator

    Mar 31, 2012
    17,763
    4,800
    Using 4-bit 2-complement representation, 5 + 3 = -8, right?

    If that a correct result (in terms of normal arithmetic)?

    If the answer is no, then an overflow has occured, otherwise an overlow hasn't occured.

    It's really that simple.
     
  7. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    If overflow occurs, means we do not need to care for the result or the output ? We can ignore ?

    Thanks !
     
  8. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,395
    497
    If overflow occurs, then the number that you just calculated will mess up some other future calculation, which in turn can result in nothing or a nuclear disaster if the system that had the overflow is part of nuclear reactor control system.

    You are the designer. If overflow is ok with you, then it is ok with us. If it kills you, we don't care.
     
  9. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    Okay!

    Noted and thanks ! :)

    So it is better to ignore the output that overflow :D
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,363
    How did you arrive at that conclusion?

    If an overflow occurred and the result is incorrect then you have a problem.
     
  11. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    In my case of study which I am currently learning digital electronics theory. So we are taught to ignore the output if overflows happen and we are not taught on how to fix that yet.

    Thanks :)
     
  12. WBahn

    Moderator

    Mar 31, 2012
    17,763
    4,800
    What do you mean by "ignore"? Just pretend nothing happened and proceed on with the calculations?

    What is the most appropriate thing to do depends on the application in question and what the consequences are of the various options.
     
  13. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    I mean just stated there output is invalid.

    Thanks !
     
  14. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,363
    No. There can be serious consequences depending on the application if an overflow occurs.

    One approach is to ensure that an overflow never occurs.
     
  15. WBahn

    Moderator

    Mar 31, 2012
    17,763
    4,800
    Okay, so output is invalid. What is your system going to do? Issue an error message? Lock up? Use a default value? What?
     
Loading...