Chapter 6: Instructions 79
Instruction
Mnemonic Subtraction Range
Bit
■ Byte
SUB
DSUB
SUBB
DSUBB
Decimal subtraction (SUB, DSUB)
BCD subtraction (SUBB, DSUBB)
■ Word
Ladder
D = S1 - S2
Decimal: S1 = 34 and S2 = 19
Hexadecimal: S1 = $22 and S2 = $13
SUB Example:
Decimal: 34 - 19 = 15
SUBB Example:
BCD: $22 - $13 = $09
Description
1. Subtract the data in S2 from S1, then store the result in the D register.
2. When using SUB and SUBB, the calculation ranges are as follows:
S1: 0 to 255 (0 to $FF)
S2: 0 to 255 (0 to $FF)
D: 0 to 255 (0 to $FF)
3. When using DSUB and DSUBB, the calculation ranges are as follows:
S1: 0 to 65,535 (0 to $FFFF)
S2: 0 to 65,535 (0 to $FFFF)
D: 0 to 65,535 (0 to $FFFF)
4. If the result exceeds the range of calculation, a carry occurs. The carry flag (F1.8) is changed
to On.
5. This operation will occur on every scan for which the input condition is true (On). To perform
the operation only on a change of input condition, use the rising/falling edge contact.
Example
Program Expression Operation Results
Initial conditions: W0 = 00016 = $0010
W1 = 00520 = $0208
W2 = 00007 = $0007
W3 = 00384 = $0180
Operation results: W10 = 00009 = $0009
W11 = 00136 = $0088
W12 = 00003 = $0003
SUB
D =
S1 =
S2 =
R
R
SUBB
D =
S1 =
S2 =
SUB
D = W10
S1 = W0
S2 = W2
DSUB
D = W11
S1 = W1
S2 = W3
SUBB
D = W12
S1 = W0
S2 = W2
R0
R
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com