Propeller Manual

Table Of Contents
3: Assembly Language Reference – SUBSX
Propeller Manual v1.1 · Page 353
(ex: SUBSX). Make sure to use the WC, and optionally WZ, effect on the leading SUB and SUBX
instructions.
For example, a signed double-long (64-bit) subtraction may look like this:
sub XLow, YLow wc wz 'Subtract low longs; save C and Z
subsx XHigh, YHigh 'Subtract high longs
After executing the above, the double-long (64-bit) result is in the long registers
XHigh:XLow. If XHigh:XLow started out as $0000_0000:0000_0001 (1) and YHigh:YLow
was $0000_0000:0000_0002 (2) the result in XHigh:XLow would be
$FFFF_FFFF:FFFF_FFFF (-1). This is demonstrated below.
Hexadecimal Decimal
(high) (low)
(XHigh:XLow) $0000_0000:0000_0001 1
- (YHigh:YLow) - $0000_0000:0000_0002 - 2
---------------------- ---------------
= $FFFF_FFFF:FFFF_FFFF = -1
A signed triple-long (96-bit) subtraction would look similar but with a SUBX instruction
inserted between the
SUB and SUBSX instructions:
sub XLow, YLow wc wz 'Subtract low longs; save C and Z
subx XMid, YMid wc wz 'Subtract middle longs; save C and Z
subsx XHigh, YHigh 'Subtract high longs
Of course, it may be necessary to specify the WC and WZ effects on the final instruction, SUBSX,
in order to watch for a result of zero or signed overflow condition. Note that during this
multi-step operation the Z flag always indicates if the result is turning out to be zero, but the
C flag indicates unsigned borrows until the final instruction,
SUBSX, in which it indicates
signed overflow.
For
SUBSX, if the WZ effect is specified, the Z flag is set (1) if Z was previously set and
SValue1 (SValue2 + C) equals zero (use
WC and WZ on preceding SUB and SUBX instructions).
If the
WC effect is specified, the C flag is set (1) if the subtraction resulted in a signed
overflow. The result is written to SValue1 unless the
NR effect is specified).