CMPS

Instruction: Compare two signed values.

CMPS SValue1, < # >SValue2


Result: Optionally, equality and greater/lesser status is written to the Z and C flags.

  • SValue1 (d-field) is the register containing the value to compare with that of SValue2.
  • SValue2 (s-field) is a register or a 9-bit literal whose value is compared with SValue1.

Opcode Table:

–INSTR–  ZCRI –CON–    –DEST–         –SRC–

Z Result

C Result

Result

Clocks

 110000    000i    1111    ddddddddd    sssssssss

D = S

Signed (D < S)

Not Written

4

Concise Truth Table:

In

Out

Destination

Source

Z

C

Effects

Destination1

Z

C

$0000_0003; 3

$0000_0002; 2

-

-

wr wz wc

$0000_0001; 1

0

0

$0000_0003; 3

$0000_0003; 3

-

-

wr wz wc

$0000_0000; 0

1

0

$0000_0003; 3

$0000_0004; 4

-

-

wr wz wc

$FFFF_FFFF; -1

0

1

$8000_0000; -2,147,483,648

$7FFF_FFFF; 2,147,483,647

-

-

wr wz wc

$0000_0001; 1

0

0 12

$7FFF_FFFF; 2,147,483,647

$8000_0000; -2,147,483,648

-

-

wr wz wc

$FFFF_FFFF; -1

0

02

$8000_0000; -2,147,483,648

$0000_0001; 1

-

-

wr wz wc

$7FFF_FFFF; 2,147,483,6473

0

1

$7FFF_FFFF; 2,147,483,647

$FFFF_FFFF; -1

-

-

wr wz wc

$8000_0000; -2,147,483,6483

0

0

$FFFF_FFFE; -2

$FFFF_FFFF; -1

-

-

wr wz wc

$FFFF_FFFF; -1

0

1

$FFFF_FFFE; -2

$FFFF_FFFE; -2

-

-

wr wz wc

$0000_0000; 0

1

0

$FFFF_FFFE; -2

$FFFF_FFFD; -3

-

-

wr wz wc

$0000_0001; 1

0

0

1 Destination is not written unless the WR effect is given.
2 The C flag result of CMPS (Compare Signed) may differ from CMP (Compare Unsigned) where the "interpreted sign" of Source and Destination are opposite. The first example in the second group, above, shows that CMPS sets C because signed $8000_0000 ( 2,147,483,648) is less than signed $7FFF_FFFF (2,147,483,647). CMP, however, would have cleared C because unsigned $8000_0000 (2,147,483,648) is not less than unsigned $7FFF_FFFF (2,147,483,647). The second example is the complementary case where the Source and Destination values are switched.
3 The examples of the third group, above, demonstrate cases where the comparison is properly reflected in the flags but the Destination Out has crossed the signed border (signed overflow error) in either the negative or positive direction. This signed overflow condition can not be reflected in the flags. If this condition is important to an application, perform a CMPS without a WR effect, note C's status (signed borrow), then perform a SUBS and note C's status (signed overflow).

Explanation

CMPS (Compare Signed) compares the signed values of SValue1 and SValue2. The Z and C flags, if written, indicate the relative equal, and greater or lesser relationship between the two.
If the WZ effect is specified, the Z flag is set (1) if SValue1 equals SValue2. If the WC effect is specified, the C flag is set (1) if SValue1 is less than SValue2.

To compare signed, multi-long values, instead of using CMPS, use CMP, possibly CMPX, and finally CMPSX. See CMPSX for more information.

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.