How to distinguish between CPU and natural overflow carry?

How to distinguish between CPU and natural overflow carry?

Before learning complement when it touches learned the basic concepts, but we found that there is unclear when contacted recently, it is also under study

Today the core of the problem, " the CPU is how to distinguish between high and overflow naturally give up? "

First conclusions are given: If the operation, the most significant bit value (that is, there is the second positive number sign) and the sign bit (that is, the first positive number) at the same time carry, it is natural discarded. Between the two if only one carry, is the overflow.

Let's explain. All cases operations can be divided into four categories:

  1. Carry the sign bit, the carry bit is not the highest values
  2. It does not carry the sign bit, the highest value bit carry
  3. Sign bit and the carry bits are the highest values
  4. And the sign bit value of the most significant bit carry no

For the fourth case, nothing to say, and do not carry, then the fundamental problem involving less than distinguished.

For the first and second cases are easy to understand: In the first case, the highest level since the value did not enter, then the sign bit of the sign is necessarily entirely due to bit, that is the sign bit must be two 1, then the result is that such carry 0-- two negative sign bit addition result is positive, overflow of course. The second is the same reason, carry the highest value and the sign bit did not enter, only shows two original sign bit is 0, then the number is the sum of two positive result is negative, overflow no doubt.

Bit more complicated is the case 3, it can be broken down as follows:

  1. Two bits are a number of symbols
  2. A sign bit is 1, and the other is 0

Talk clearly the content here, we have to look at what is overflow? Our 4-bit binary number, for example, it indicates the range [-8,7]. Note that the overflow is the result of an error, but not binary adder itself is wrong, we call overflow, refers to the results of binary addition interception, Results and arithmetic operations taken does not match, but the cause of the overflow is calculated the result exceeds the range that can be represented. For case 2, a positive and negative numbers represent the sum of a correct representation of the right, the result must not exceed the range represented, where the carry bit can only be a naturally. For 1, adding two negative numbers will overflow under what circumstances it? Is represented beyond the range of the case, and for negative numbers, in addition to the sign bit, the bit value of the majority of the smaller 0. In the premise 1, to find the minimum negative number is 1010 and 1110, -6 and -2 respectively, do not add up to exactly -8-range. So this case has also been proven not overflow.

In summary, we show only the top two there is only one bit of carry overflow when is the sign bit and value, followed as far as we can design a CPU instruction.

Guess you like

Origin www.cnblogs.com/jiading/p/11546524.html