ASSEMBLY LANGUAGE REFERENCE
Multi-Long ADD/SUB/CMP Operations
Many useful integer quantities fit within 32 bits of space (0 to 4,294,967,295 or -2,147,483,648 to +2,147,483,647).
This wide range means the majority of integer add/subtract/compare operations are achieved in just one step
using a single 32-bit signed or unsigned math instruction; a single-long operation. However, if any such operation
will use or create values larger than 32 bits, multiple math instructions must be chained together to form a
multi-long "extended" operation; two instructions for 64-bits, three instructions for 96-bits, etc.
Adding Two Multi-Long Values
To add two 64-bit values, use an unsigned ADD instruction (regardless of the values' unsigned or signed nature)
followed by either an unsigned-extended ADDX or signed-extended ADDSX instruction, for unsigned or signed
numbers, respectively. If the two values are larger than 64 bits in size (regardless of their signed/unsigned format)
insert one ADDX instruction per extra 32-bits in-between the first and last instruction.
Make sure to also use the WC or WCZ effect on the leading ADD and ADDX instructions so that the final ADDX or
ADDSX instruction works properly.
64-bit Unsigned Add
An unsigned double-long (64-bit) addition looks like this:
add XLow, YLow wcz 'Add low longs; save C (required) and Z (optional)
addx XHigh, YHigh wcz 'Add high longs; save C and Z (both optional)
Note: the optional flag effects are only required if the intent is to monitor for zero or an unsigned overflow.
After executing the above, the full double-long (64-bit) result is in the registers XHigh:XLow. If XHigh:XLow started
out as $0000_0000:FFFF_FFFF (4,294,967,295) and YHigh:YLow was $0000_0000:0000_0001 (1), the result in
XHigh:XLow would be $0000_0001:0000_0000 (4,294,967,296). This is demonstrated below.
Hexadecimal Decimal
(high) (low)
(XHigh:XLow) $0000_0000:FFFF_FFFF 4,294,967,295
+ (YHigh:YLow) + $0000_0000:0000_0001 + 1
─────────────────── ──────────────
= $0000_0001:0000_0000 = 4,294,967,296
An unsigned triple-long (96-bit) addition would look similar but with another ADDX instruction inserted between
the ADD and ADDX instructions:
add XLow, YLow wcz 'Add low longs; save C (required) and Z (optional)
addx XMid, YMid wcz 'Add middle longs; save C (required) and Z (optional)
addx XHigh, YHigh wcz 'Add high longs; save C and Z (both optional)
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 carries until the final ADDX instruction, in which it indicates unsigned overflow (if any).
64-bit Signed Add
In comparison to the above, a signed double-long (64-bit) addition uses an ADDSX instead of ADDX as the last
instruction:
Copyright © Parallax Inc. 2022/11/01 ▪ Propeller 2 Assembly Language Manual ▪ Page 11