Nagavi Bindzuriani
Nagavi Bindzuriani

Reputation: 77

Sub instruction and affected flags on x86: can SUB set SF != CF?

Since documentation doesn't really describe how the flags are affected, I couldn't figure out what's the difference between carry and signed flag during sub instruction, it seems like whenever a < b in sub a, b both carry and signed flags will be set. Is there a case where signed flag will be set without carry (or vice versa) during sub instruction ?

Upvotes: 1

Views: 5261

Answers (1)

Michael
Michael

Reputation: 58487

Is there a case where signed flag will be set without carry (or vice versa) during sub instruction ?

Sure:

mov al,0xFE
sub al,2

The result is 0xFC, which when viewed as signed 8-bit is -4. So the SF will be set, buf CF will be clear (carry can be viewed as "unsigned less than", and 0xFE is obviously not unsigned less than 2).

Upvotes: 3

Related Questions