Overview

A number of instructions operate with respect to the condition code registers.

CMP and TEST

InstructionOperandsBased OnDescription
cmp[bwlq]Compare
test[bwlq]Test

SET

The description of the SET commands apply to the case of a comparison instruction. That is, the condition codes are set according to computation t = a - b, where t, a, and b may be interpreted as signed or unsigned depending on the SET instruction invoked.

InstructionSynonymEvaluationDescription
setesetzZFEqual / zero
setnesetnz~ZFNot equal / not zero
setsSFNegative
setns~SFNonnegative
setlsetngeSF ^ OFLess (signed <)
setlesetng(SF ^ OF) | ZFLess or equal (signed <=)
setgsetnle~(SF ^ OF) & ~ZFGreater (signed >)
setgesetnl~(SF ^ OF)Greater or equal (signed <=)
setbsetnaeCFBelow (unsigned <)
setbesetnaCF | ZFBelow or equal (unsigned <=)
setasetnbe~CF & ~ZFAbove (unsigned >)
setaesetnb~CFAbove or equal (unsigned >=)

Note how the other condition code evaluations are easy to derive from setl and setb.

Bibliography

  • Bryant, Randal E., and David O’Hallaron. Computer Systems: A Programmer’s Perspective. Third edition, Global edition. Always Learning. Pearson, 2016.