Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - The difference between overflow and carry in assembly language
The difference between overflow and carry in assembly language

I learned natural numbers and integers in primary school.

After being stored in the computer, it is renamed: unsigned number, signed number.

No matter what number, in the computer, it is represented and stored in "binary machine code".

8-bit binary machine code can represent

The range of unsigned numbers is: 0~255.

The range of signed numbers is: -128~+127.

When the operation result exceeds the above range, it will inevitably overflow.

Overflow should be a common noun.

However, in the CPU designed by Intel, it is divided into two terms: "carry" and "overflow".

----------------------------------------------

When Intel designed the CPU, it specified two flag bits.

If the unsigned number operation result exceeds the upper and lower limits, there will be: CF = 1, which is called "carry".

If the result of a signed number operation exceeds the upper and lower limits, there will be: OF = 1, which is called "overflow".

The schematic diagram is as follows:

Whether CF=1 or OF=1 appears, it means that the operation result has exceeded the 8-bit binary accommodation range.

Then, it is definitely wrong to use only 8-bit binary as the operation result.

For unsigned numbers, including CF=1, the result is 9 bits, which is correct.

However, for signed number operations, once OF=1, the correct result cannot be obtained.