CMPSUB
Instruction: Compare two unsigned values and subtract the second if it is lesser or equal.
CMPSUB Value1, < # >Value2
Result: Optionally, Value1 = Value1 – Value2, and Z and C flags = comparison results.
- Value1 (d-field) is the register containing the value to compare with that of Value2 and is the destination in which to write the result if a subtraction is performed.
- Value2 (s-field) is a register or a 9-bit literal whose value is compared with and possibly subtracted from Value1.
Opcode Table:
–INSTR– ZCRI –CON– –DEST– –SRC– | Z Result | C Result | Result | Clocks |
111000 001i 1111 ddddddddd sssssssss | D = S | Unsigned (D => S) | Written | 4 |
Concise Truth Table:
In | Out | ||||||
Destination1 | Source1 | Z | C | Effects | Destination | Z | C |
$0000_0003; 3 | $0000_0002; 2 | - | - | wz wc | $0000_0001; 1 | 0 | 1 |
$0000_0003; 3 | $0000_0003; 3 | - | - | wz wc | $0000_0000; 0 | 1 | 1 |
$0000_0003; 3 | $0000_0004; 4 | - | - | wz wc | $0000_0003; 3 | 0 | 0 |
1 Both Source and Destination are treated as unsigned values.
Explanation
CMPSUB compares the unsigned values of Value1 and Value2, and if Value2 is equal to or less than Value1 then it is subtracted from Value1.
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 a subtraction is possible (Value1 is equal to or greater than Value2). The result, if any, 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.