Basic Function Instruction
6-27
FUN 12 D P
(−)
SUBTRACTION
(Performs subtraction of the data specified at Sa and Sb and stores the result in D)
FUN 12 D P
(−)
Symbol
Operand
Sa: Minuend
Sb: Subtrahend
D : Destination register to store the
results of the subtraction
Sa, Sb, D may combine with V, Z, P0~P9
to serve indirect addressing
WX WY WM WS TMR CTR HR IR OR SR ROR DR K XR
Range
Ope-
rand
WX0
∣
WX240
WY0
∣
WY240
WM0
∣
WM1896
WS0
∣
WS984
T0
∣
T255
C0
∣
C255
R0
∣
R3839
R3840
∣
R3903
R3904
∣
R3967
R3968
∣
R4167
R5000
∣
R8071
D0
∣
D4095
16/32-bit
+/− number
V、Z
P0~P9
Sa ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Sb ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
D ○ ○ ○ ○ ○ ○ ○ ○* ○* ○ ○
Description
● Performs the subtraction of the data specified at Sa and Sb and writes the results to a specified register D
when the subtract control input "EN" =1 or "EN↑" ( P instruction) from 0 to 1. If the result of subtraction is
equal to 0 then set FO0 to 1. If carry occurs (subtracting a negative number from a positive number and the
result exceeds 32767 or 2147483647), then set FO1 to 1. If borrow occurs (subtracting a positive number
from a negative number and the resulted difference is less than -32768 or -2147483648), then set FO2 to 1.
All the FO statuses are retained until this instruction is executed again and overwritten by a new result.
Example 16-bit subtraction
Ladder Diagram Key Operations Mnemonic Codes
X0
EN
R
R
R
0
1
2
12P.(-)
D=0
CY
BR
Y2
U/S
Sa :
Sb :
D :
OUT
ORG
ORG X 0
FUN 12
Sa: R 0
Sb: R 1
D: R 2
FO 2
OUT Y 2
Sa R0 -5
Sb R1 32767
R0-R1=-32772
Ø
X0=1
D R2 -4
-32768-4=-32772
Y2=1(borrow 1 represents-32768)Please refer to section 6.5