How to Set overflow flag for CPU

Source: Internet
Author: User

 

For example

MoV Al, 0ffh

Add Al, 1

 

The result is carried, but it does not overflow. It can be seen that the overflow mark is mainly used for symbolic operations. 0ffh is-1 as the number of symbols, and-1 + 1 = 0, of course, there is no overflow.

 

2. We know that there is no difference between the number of signed instances and the number of unsigned instances in the CPU computing process. How can we determine if an operation exceeds the number range of the table?

 

The answer is:

It performs the XOR operation on the carry state of the maximum two digits of the destination operand during the operation as the result.

 

For example

MoV Al, 0ffh

Add Al, 1

 

11111111o

+ 00000001o

7---------------------0 bits

^

7 bits with a forward position 1

6 bits with 1 bits

1 XOR 1 = 0 so of = 0

 

Example 2

MoV Al, 080 H

Add Al, 080 H

 

0000000o

+ 0000000o

7--------------------0 bits

 

7 bits with a forward position 1

6 bits without carry 0

1 XOR 0 = 1 so of = 1

 

Therefore, this operation overflows. The value of 080h as the number of symbols is-128-128 +-128 =-256, which obviously exceeds the number range of single-byte number tables.

-128 +-1 should also overflow.

Let's verify it.

The complement of One-byte-1 indicates 0 FFH.

 

That is

MoV Al, 080 H

Add Al, 0ffh

 

10000000

+ 11111111

7---------------0 bits

 

7 bits with a forward position 1

6 bits without carry 0

1 XOR 0 = 1 so of = 1 overflows.

 

There must be a mathematical principle. I will not study it for the time being.

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.