Propeller Manual

Table Of Contents
3: Assembly Language Reference – CMPX
Propeller Manual v1.1 · Page 281
4
The C flag result of CMPX (Compare Unsigned, Extended) may differ from CMPSX (Compare Signed, Extended) where the
“interpreted sign” of Source and Destination are opposite. The first example in the second group, above, shows that CMPX clears
C because unsigned $8000_0000 (2,147,483,648) is not
less than unsigned $7FFF_FFFF (2,147,483,647). CMPSX, 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. Note that examples with differing Z and C are not
shown but have expected effects similar to the other examples.
Explanation
CMPX (Compare Extended) compares the unsigned values of Value1 and Value2 plus C. The Z
and C flags, if written, indicate the relative equal, and greater or lesser relationship between
the two. The
CMPX instruction is used to perform multi-long comparison; 64-bit comparisons,
for example.
In a multi-long operation, the first instruction is unsigned (ex:
CMP), any middle instructions
are unsigned, extended (ex:
CMPX), and the last instruction is unsigned, extended (CMPX) or
signed, extended (
CMPSX) depending on the nature of the original multi-long values. We’ll
discuss unsigned multi-long values here; see
CMPSX on page 277 for examples with signed,
multi-long values. Make sure to use the
WC, and optionally WZ, effect on all the instructions in
the comparison operation.
For example, an unsigned double-long (64-bit) comparison may look like this:
cmp XLow, YLow wc wz 'Compare low longs; save C and Z
cmpx XHigh, YHigh wc wz 'Compare high longs
After executing the above, the C and Z flags will indicate the relationship between the two
double-long (64-bit) values. If XHigh:XLow started out as $0000_0001:0000_0000
(4,294,967,296) and YHigh:YLow was $0000_0000:0000_0001 (1) the resulting flags would
be: Z = 0 and C = 0; (Value1 > Value2). This is demonstrated below. Note that the
comparison is really just a subtraction with the result not written; the Z and C flag result is
important, however.
Hexadecimal Decimal Flags
(high) (low)
(XHigh:XLow) $0000_0001:0000_0000 4,294,967,296 n/a
- (YHigh:YLow) - $0000_0000:0000_0001 - 1 n/a
---------------------- --------------- --------
= $0000_0000:FFFF_FFFF = 4,294,967,295 Z=0, C=0
For CMPX, if the WZ effect is specified, the Z flag is set (1) if Z was previously set and Value1
equals Value2 + C (use
WC and WZ on preceding CMP and CMPX instructions). If the WC effect is
specified, the C flag is set (1) if Value1 is less than Value2 (as multi-long values).