Complement and arithmetic right shift command

Source: Internet
Author: User

 

Complement and arithmetic right shift command

Supplemental Discussion

The advantage of complement makes the original code with the highest bit redundant. A positive complement is itself, and a negative complement is obtained by completing its absolute value. The return operation is to reverse the value by bit and add one more. Do not confuse it with the concept of complement code. It has many excellent features.

The complement process is the same as the reverse complement process. That is to say, after a number is supplemented twice, it is still the number itself. The physical meaning of code completion is well understood. You can also analyze the complement operation process. After a number is reversed by bit, add 1. Then, the system starts to carry from the forward bit to the high bit until it is zero, it is impossible to carry to a higher position (of course, there is an extreme case where the complement is 0, and the result of 0 is itself, so you can leave it alone ). The result is that the lowest number of digits is reversed, and the form of these digits should be 1 plus a number of zeros (of course, it can be 0 ). The bitwise affected by the addition of 1 is equivalent to being reversed twice, that is, the result is what they are. The portion not affected by the addition of 1 is reversed once. Perform a complement operation again to see what results will appear. First, the inverse is obtained. In this way, the first part is retrieved twice, but the original appearance is restored. The form obtained after the first part is reversed is a 0 with several 1 (it can be 0 1). This form will be reversed after 1 is added, it does not affect other parts. In this way, the original appearance is restored. So the entire number is restored.

It is easy to determine whether the settlement overflows when addition operations are performed using the complement code. The determination method is to calculate the difference or between the second high and the highest bit to its high. If the result is 0, it indicates normal; otherwise, it indicates overflow. There are no more than two overflow situations, when two positive numbers and two negative numbers are added respectively. When the sum of two positive numbers is a secondary high carry, it is obviously an overflow situation. When the highest bit is 0, it cannot be carried again. In this way, the carry XOR or result is 1, reflecting overflow; when the two negative numbers are added, the highest bit must have an increment. In this way, the variance or result is 1 only when the secondary high cannot be carried. In this case, overflow occurs. The absolute value of a negative number can be regarded as the oil in the tank, and the part after the complement Code except the highest bit can be regarded as the remaining space in the tank. When two tanks of oil are poured into a bucket, if the remaining space is not enough, the oil will surely overflow.

 

Arithmetic shift right instruction

The shift arithmetic right operation of the arithmetic right shift command is to shift the value in the register to the right, and fill the leftmost end with the highest bit instead of the zero. Here we will analyze why it does not directly add zero. To facilitate the discussion, consider shifting one digit to the right. Similar analysis can also be performed when several digits are shifted to the right.

The root cause of not directly completing zero is to not change the numeric symbol and make the numeric value half of the original one. As we all know, the number of symbols is stored in the computer as a complement. The positive complement is itself, and the highest bit is 0. When one digit is shifted to the right, the value of the highest digit is halved. There is no problem. For a negative number, its complement is obtained after completing its absolute value. If the maximum bit is supplemented by 1, it is also equivalent to the next high bit to supplemented by 1. Can the result be halved? It depends on whether the original code after the right shift is half of the original code. That is, whether it is 0 at the highest and secondary highs. To view the original code, you only need to perform a supplement to the result. The first step of completing is to take the inverse, so that the filling of 1 becomes 0, no problem occurs, but you have to see Step 2 and Add 1. In which cases does the addition of 1 affect the next high position? The answer is only two numbers. When the original complement Code except the highest bit and the lowest Bit are both 0, after the first bit is shifted to the right, all except the highest bit are 0. After seeking for a complement, these 0 values are changed to 1, and after adding 1, carry will affect the secondary high to 1 (after the inverse, the secondary high is set to 0), and the secondary high of the original code should be filled with 0, in this way, the original number cannot be reduced. Take the four-digit number as an example. 1000 if the computer is to be regarded as the number of symbols, it will be regarded as-16! The other number, because there is 1 in the middle part, is changed to 0 after the inversion, and the carry after the addition of 1 cannot affect the secondary high. All the results can be reduced to the original number without changing the symbol.

There are not many scenarios for computer complementing. One is when the number in the command contains a negative number, but if there is a negative 0 in the command, that is, the '-0' assembler will change it to 0. The second is the subtraction operation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.