Article 2 Overflow signs CF and

Source: Internet
Author: User

In Assembly Learning, I personally feel that the overflow signs of CF and of are still a little hard to understand. I am still confused. If there is any error,

Please correct me!

 

I. Keep in mind the learning of CF and. Cf indicates an unsigned number overflow sign, and of indicates a signed number overflow sign.

In other words, even if the sum or subtraction of signed numbers causes cf = 1, it makes no sense. It does not indicate whether the result is correct or not. At this time, of = 1,

The result overflows with an error. Of = 0 indicates that the result is correct. This process has nothing to do with CF. cf = 1/0 will not affect it. Likewise

We can conclude that of does not affect the number of unsigned characters.

For example:

[9-6] fill = [9] fill-[6] fill = [9] fill + [-6] fill

[9]-[6]

00001001

-00000110

------

00000011

In this case, of = 0, cf = 0

 

[9] population + [-6] population

00001001

+ 11111010

------

1 00000011

In this case, of = 0, cf = 1

You may have discovered that it is not completely equivalent to convert subtraction into addition by using formulas, because CF is different.

Otherwise, the CF value does not affect the result. In this case, both addition and subtraction are signed numbers. No matter cf = 1/0, As long as of = 0,

The results are correct. Of course, there is another point worth noting. After all, CF has different values in the two calculation methods.

The execution of the program may be affected.

 

Ii. Briefly introduce the calculation method of CF and

1. Cf judgment

① Addition

Decimal angle. If the two unsigned numbers are added and the result is greater than 2 ^ N-1 (n is the number of digits), cf = 1; otherwise, cf = 0;

Binary angle. If the two unsigned numbers are added and the highest bit has a forward bitwise, cf = 1; otherwise, cf = 0.

② Subtraction

Decimal angle. If the two unsigned numbers are subtracted and the subtraction is greater than the subtrahend (that is, the result is not within 0-2 ^ N-1), cf = 1; otherwise, cf = 0;

Binary angle. If the two unsigned digits are subtracted, the maximum bits are used for the forward game. cf = 1; otherwise, cf = 0.

2. Of Judgment

① Addition

Decimal angle. If the two signed numbers are added, the result is not in-2 ^ (n-1 )~ 2 ^ (n-1)-1, then of = 1, otherwise of = 0;

Binary angle. If the two signed numbers are the same, and the result of the addition is the same as that of the two signed numbers, then of = 1; otherwise, of = 0.

② Subtraction

Decimal angle, if the result of the subtraction of the signed number is-2 ^ (n-1 )~ 2 ^ (n-1)-1, then of = 1, otherwise of = 0;

Binary angle. If there are two different numbers, and the subtraction result is opposite to the subtrahend, of = 1; otherwise, of = 0.

 

3. It is worth mentioning that the computing rules introduced in the second part are all for convenience of human computing. In the computer,

The CPU does not know whether the number involved in the operation is signed or unsigned. It is only calculated according to certain instructions and rules,

Then set and use the flag.

 

 

 

 

 

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.