SUBX
Instruction: Subtract unsigned value plus C from another unsigned value.
SUBX Value1, < # > Value2
Result: Difference of unsigned Value1, and unsigned Value2 plus C flag, is stored in Value1.
- Value1 (d-field) is the register containing the value to subtract Value2 plus C from, and is the destination in which to write the result.
- Value2 (s-field) is a register or a 9-bit literal whose value plus C is subtracted from Value1.
Opcode Table:
–INSTR– ZCRI –CON– –DEST– –SRC– | Z Result | C Result | Result | Clocks |
110011 001i 1111 ddddddddd sssssssss | Z & (D–(S+C) = 0) | Unsigned Borrow | Written | 4 |
Concise Truth Table:
In | Out | ||||||
Destination1 | Source1 | Z | C | Effects | Destination | Z | C |
$0000_0001; 1 | $0000_0001; 1 | 0 | 0 | wz wc | $0000_0000; 0 | 0 | 0 |
$0000_0001; 1 | $0000_0001; 1 | 1 | 0 | wz wc | $0000_0000; 0 | 1 | 0 |
$0000_0001; 1 | $0000_0001; 1 | x | 1 | wz wc | $FFFF_FFFF; 4,294,967,295 | 0 | 1 |
1 Both Source and Destination are treated as unsigned values.
Explanation
SUBX (Subtract Extended) subtracts the unsigned value of Value2 plus C from the unsigned Value1 and stores the result into the Value1 register. The SUBX instruction is used to perform multi long subtraction; 64-bit subtractions, for example.
In a multi-long operation, the first instruction is unsigned (ex: SUB), any middle instructions are unsigned, extended (ex: SUBX), and the last instruction is unsigned, extended (SUBX) or signed, extended (SUBSX) depending on the nature of the original multi-long values. We'll discuss unsigned multi-long values here; see SUBSX for examples with signed, multi-long values. Make sure to use the WC, and optionally WZ, effect on the leading SUB and SUBX instructions.
For example, an unsigned double-long (64-bit) subtraction may look like this:
sub XLow, YLow wc wz 'Subtract low longs; save C and Z subx 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_0001:0000_0000 (4,294,967,296) and YHigh:YLow was $0000_0000:0000_0001 (1) the result in XHigh:XLow would be $0000_0000:FFFF_FFFF (4,294,967,295). This is demonstrated below.
Hexadecimal Decimal (high) (low) (XHigh:XLow) $0000_0001:0000_0000 4,294,967,296 - (YHigh:YLow) - $0000_0000:0000_0001 - 1 ---------------------- --------------- = $0000_0000:FFFF_FFFF = 4,294,967,295
Of course, it may be necessary to specify the WC and WZ effects on the final instruction, SUBX, in order to watch for a result of zero or an unsigned borrow condition.
For SUBX, if the WZ effect is specified, the Z flag is set (1) if Z was previously set and Value1 (Value2 + 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 an unsigned borrow (32-bit overflow). The result is written to Value1 unless the NR effect is specified.
Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.