Question

If I have the following table:

Case 1:    x: 42           y: -15           (y-x) = -57 
Case 2:    x: -17          y: -17           (y-x) = 0
Case 3:    x: 0x7ffffffd   y: -67           (y-x) = 2147483584
Case 4:    x: 67           y: -0x7fffffffd  (y-x) = 2147483584

What would the condition code flags set (zero or one, per flag) for ZF SF OF and CF

when considering the instruction: cmp1 %eax %ecx if %eax contains x and %ecx contains y?

I understand that cmp1 ...,... is executed by: cmp1 SRC2,SRC1

which means: "sets condition codes of SRC1SRC2"

I understand that the flags represent:

OF = overflow (?)
ZF = zero flag i.e. zero...
CF = carry out from msb
SF - sign flag i.e. negative

For my four cases in the table, I believe the flags would be:

1) ZF = 0 SF = 1 CF = 0 OF = ?
2) ZF = 1 SF = 0 CF = 0 OF = ?
3) ZF = 0 SF = 0 CF = 1 OF = ?
4) ZF = 0 SF = 0 CF = 1 OF = ?

Am I correct? Please explain what CF and OF are and how to determine if either will be set TRUE, and correct any of my flawed understanding. Thank you.

Was it helpful?

Solution

Carry overflow occurs when an arithmetic operation generates a carry that cannot fit into the register. So if you had 8-bit registers, and wanted to add 10000000 and 10000000 (unsigned):

 10000000
 10000000
 --------
100000000

This 1 is the carry from most significant bit, and thus sets CF = 1.

You might also want to check this other answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top