top decor
Instruction set Compare instructions


Many branch algorithms need to compare numbers in order to select further data proceeding. MMIX has several kinds of compare instructions, which are shown in the following table.

The main action every compare instruction does is setting the result register X according the comparison outcome:

  • -1 is set when $Y is less than $Z (or Z constant)
  • 0 is set when operands are equal and
  • 1 otherwise ($Y > $Z)
In other words computer calculates the sign of the difference $Y - $Z (or $Y - Z).

Note that comparison of integer and float numbers are essentially different procedures. Besides the last one additionally checks operands for NAN value and reset $X to 0 if either $Y or $Z is NAN.

CodeMnemonicName Comments
30CMP $X, $Y, $Z comparecompare signed value from register Y with register Z and code the result into register X
31CMP $X, $Y, Z comparecompare signed value from register Y with constant Z and code the result into register X
32CMPU $X, $Y, $Z compare unsignedcompare unsigned value from register Y with register Z and code the result into register X
33CMPU $X, $Y, Z compare unsignedcompare unsigned value from register Y with constant Z and code the result into register X
01FCMP $X, $Y, $Z floating compare compare float values from registers Y and Z; the result is coding into register X

To applet
Examples:

  • instruction CMP $1, $2, $3 compares signed integer values from registers 2 and 3, calculates sign of the difference and stored it into register 1
  • instruction CMP $1, $2, 3 compares signed integer value from register 2 with number 3
  • instruction FCMP $1, $2, $3 compares float values from registers 2 and 3 and codes the results to register X as described above


Related topics:

"MMIX basics" page
 

  (C) 2002, Evgeny Eremin. rEd-MMI project documentation