CMP

Instruction: Compare two unsigned values.

CMP Value1, < # > Value2


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

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

Opcode Table:

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

Z Result

C Result

Result

Clocks

 100001    000i    1111    ddddddddd    sssssssss

D = S

Unsigned (D < S)

Not Written

4

Concise Truth Table:

In

Out

Destination1

Source1

Z

C

Effects

Destination2

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; -13

0

1

$8000_0000; 2,147,483,648

$7FFF_FFFF; 2,147,483,647

-

-

wr wz wc

$0000_0001; 1

0

04

$7FFF_FFFF; 2,147,483,647

$8000_0000; 2,147,483,648

-

-

wr wz wc

$FFFF_FFFF; -13

0

14

$FFFF_FFFE; 4,294,967,294

$FFFF_FFFF; 4,294,967,295

-

-

wr wz wc

$FFFF_FFFF; -13

0

1

$FFFF_FFFE; 4,294,967,294

$FFFF_FFFE; 4,294,967,294

-

-

wr wz wc

$0000_0000; 0

1

0

$FFFF_FFFE; 4,294,967,294

$FFFF_FFFD; 4,294,967,293

-

-

wr wz wc

$0000_0001; 1

0

0

1 Both Source and Destination are treated as unsigned values.
2 Destination is not written unless the WR effect is given.
3 Destination Out (written Destination) may be thought of as either unsigned or signed; it is shown here as signed for demonstration purposes only.
4 The C flag result of CMP (Compare Unsigned) may differ from CMPS (Compare Signed) where the "interpreted sign" of Source and Destination are opposite. The first example in the second group, above, shows that CMP clears C because unsigned $8000_0000 (2,147,483,648) is not less than unsigned $7FFF_FFFF (2,147,483,647). CMPS, however, would have set C because signed $8000_0000 (-2,147,483,648) is less than signed $7FFF_FFFF (2,147,483,647). The second example is the complementary case where the Source and Destination values are switched.

Explanation

CMP (Compare Unsigned) compares the unsigned values of Value1 and Value2. 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 Value1 equals Value2. If the WC effect is specified, the C flag is set (1) if Value1 is less than Value2.

The result is not written unless the WR effect is specified. If WR is specified, CMP becomes exactly like a SUB instruction.

To compare unsigned, multi-long values, use CMP followed by CMPX. See CMPX for more information.

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