the_endian
the_endian

Reputation: 2527

How are the sign and overflow flags used in x86-64 assembly language to determine "less than" in CMOVL and CMOVNG?

I am reading [AMD64 Architecture Programmer's Manual Volume 1: Application Programming][1]. On page 47, which is about CMOVcc, it has a table which states:

CMOVL
CMOVNGE SF <> OF Conditional move if less
Conditional move if not greater or equal

First, I'm not sure exactly what <> means here. But I am guessing that it means "sign flag is opposite of overflow flag." So part one of my question is, "am I right?"

But my main question is, how is it determined that the definition of "less than" can be represented by the condition of these 2 flags? For example, after learning standard math in school, my brain essentially performs the following in the way described:

mov rax, 15
mov rbx, 50
cmp rbx, rax

I simply "see" that 50 is a number with greater value than 15 and instantly know that 50 is the greater number. I know this likely because the greater number has more digits, no . and no - in front of it.

However, from what I gather by what I've learned so far, the CPU can't "see" this, but instead, it performs a subtraction operation and then uses the resulting flags to "know" which number is greater and which is less.

Could someone explain how these rules regarding the sign flag and overflow flag can definitively tell me that one quantity is less than another? [1]: https://www.amd.com/system/files/TechDocs/24592.pdf

Upvotes: 0

Views: 590

Answers (1)

prl
prl

Reputation: 12432

Consider each case:

  A    B    A - B    <    S    V    
 127   1     126     F    0    0    
  1   127   -126     T    1    0
 127   -1   -128     F    1    1
-127   1    -128     T    1    0
-127   2     127     T    0    1

Upvotes: 1

Related Questions