Develop a Boolean equation for overflow detection

Overflow Detection


  1. Overflow Condition
  2. Binary Arithmetic
  3. Adding Unsigned Numbers
  4. Overflow Detection Circuit for Unsigned Addition
  5. Adding Signed Numbers
  6. The Full Adder Truth Table
  7. Adding the Sign Bits
  8. The Overfow Output
  9. Signed Numbers Addition
  10. Signed Numbers Addition, Cont.
  11. Signed Numbers Addition, Cont.
  12. Signed Numbers Addition, Cont.
  13. Signed Numbers Addition, Cont.
  14. Overflow Detection Circuit for 2's Complement Addition
  15. Misconceptions about Overflow

1. Overflow Condition


  • Arithmetic operations have a potential to run into a condition known as overflow.

  • Overflow occurs with respect to the size of the data type that must accommodate the result.

  • Overflow indicates that the result was too large or too small to fit in the original data type.

  • When two signed 2's complement numbers are added, overflow is detected if:

    1. both operands are positive and the result is negative, or

    2. both operands are negative and the result is positive.

  • When two unsigned numbers are added, overflow occurrs if

    • there is a carry out of the leftmost bit.

  •  


2. Binary Arithmetic


  • Computers don't know the difference between signed and unsigned binary numbers.

  • This is a good thing, because it makes logic circuits fast.

  • This is also a bad thing, because distinguishing between signed and unsigned is our responsibility.

  • The distinction is very important when detecting an overflow after addition or subtraction.

  • Correct approach to detect the overflow is to consider two separate cases:

    1. Overflow when adding unsigned numbers.

    1. Overflow when adding signed numbers.

  •  


3. Adding Unsigned Numbers


  1. Let's first solve the problem for addition of one-bit quntities:

         0 + 0 =  0
         0 + 1 =  1
         1 + 0 =  1
         1 + 1 = 10
    
    • The last line indicates that we have a carry output.

    • That is, one-bit quantity cannot accommodate (1 + 1).

    • Therefore, larger data type is required for (1 + 1) to succeed.

  2. When multi-bit unsigned quantities are added, overflow occurrs if there is a carry out from the leftmost (most significant) bit.

     


4. Overflow Detection Circuit for Unsigned Addition


  • Overflow detection circuit for unsigned binary addition:

      Overflow detection circuit for unsigned binary addition

     


5. Adding Signed Numbers


  • Consider overflow detection when adding two one-bit signed quntities.

  • Although one bit is required to represent the data, another bit has to represent the sign.

  • Therefore, two-bit data type is required:

BINARYDECIMAL
sign bitdata bit
000
011
11-1
10-2
  • Recall that to represent 2's complement negative number, we must

    1. Flip all bits

    2. Add 1.

  •  


6. The Full Adder Truth Table


  • Recall the truth table for the 2's complement full adder logic:

     

    INPUTSOUTPUTS
    ABCARRY INCARRY OUTSUM
    00000
    00101
    01001
    01110
    10001
    10110
    11010
    11111

     

     

  •  

     

  • The truth table includes five columns with three inputs and two outputs.

    1. input A

    2. input B

    3. carry IN for the current column

    4. resulting carry OUT (carry-over), generated for the next column

    5. the resulting SUM.

  •  


7. Adding the Sign Bits


  •  

    INPUTSOUTPUTS
    AsignBsignCARRY INCARRY OUTSUMsign
    00000
    00101
    01001
    01110
    10001
    10110
    11010
    11111

     

  •  

  • The full adder knows nothing about the difference between signed and unsigned numbers.

  • In 2's complement binary representation, the sign bit is simply the leftmost, or most significant, bit of the data type.

  • The full adder circuit will be adding the sign bit column just as any other bit.

  •  


8. The Overfow Output


  •  

    INPUTSOUTPUTS
    AsignBsignCARRY INCARRY OUTSUMsignOVERFLOW
    00000?
    00101?
    01001?
    01110?
    10001?
    10110?
    11010?
    11111?

     

  •  

  • Full adder truth table for the sign bit can be extended to include new output which indicates if overfow condition has occured.

  • Our task is to populate the OVERFLOW column with corresponding values.

  •  


9. Signed Numbers Addition


  • Two-bit signed data type:

    BINARYDECIMAL
    sign bitdata bit
    000
    011
    11-1
    10-2

     

  •  

  • Notice that when operands have opposite signs, their sum will never overflow:

        1 + -2 = -1
        1 + -1 = 0
    
  • Therefore, overflow can only occur when the operands have the same sign:

          1 + 1 = 2
        -2 + -2 = -4
        -2 + -1 = -3
    
  • None of the results  { 2, -4, -3 }  can fit into the two-bit signed data type.

  •  


10. Signed Numbers Addition, Cont.


  •  

    INPUTSOUTPUTS
    AsignBsignCARRY INCARRY OUTSUMsignOVERFLOW
    00000?
    00101?
    010010
    011100
    100010
    101100
    11010?
    11111?

     

  •  

  • When operands have opposite signs, their sum will never overflow.

  •  


11. Signed Numbers Addition, Cont.


  •  

    INPUTSOUTPUTS
    AsignBsignCARRY INCARRY OUTSUMsignOVERFLOW
    000000
    00101?
    010010
    011100
    100010
    101100
    11010?
    111110

     

  •  

  • There is no overflow, if:

    • both operands are positive and the sum is positive.

    • both operands are negative and the sum is negative.

  •  


12. Signed Numbers Addition, Cont.


  •  

    INPUTSOUTPUTS
    AsignBsignCARRY INCARRY OUTSUMsignOVERFLOW
    000000
    001011
    010010
    011100
    100010
    101100
    110101
    111110

     

  •  

  • When two signed 2's complement numbers are added, overflow is detected if:

    1. both operands are positive and the sum is negative, or

    2. both operands are negative and the sum is positive.

  •  


13. Signed Numbers Addition, Cont.


  •  

    INPUTSOUTPUTS
    AsignBsignCARRY INCARRY OUTSUMsignOVERFLOW
    000000
    001011
    010010
    011100
    100010
    101100
    110101
    111110

     

  •  

  • Notice that overflow occurs only when

    • CARRYin ≠ CARRYout

  • or simply

    • V = Cin XOR Cout

  • where V is the overflow signal.

  •  


14. Overflow Detection Circuit for 2's Complement Addition


  • Overflow detection circuit for 2's complement addition

      Overflow detection circuit for 2's complement addition

     


15. Misconceptions about Overflow


  • Specific overflow detection requires knowing the operation and the representation.

  • Overflow occurs when you do some operation to two valid representations...

    • ...and the result can not be represented in the representation because the value is too large or too smal.

  • Overflow detection is detecting overflow for a specific representation...

    • ...Too often people mistake overflow condition for unsigned overflow, when the carry out is 1.

  • Overflow detection for 2's complement addition is different:

    • One way to detect it is to XOR the carry in and the carry out.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值