7 Applied Instructions
7.3 Arithmetic and Logical Operation
184
FXCPU Structured Programming Manual
(Basic & Applied Instruction)
Program examples
1. Difference between SUB instruction and DEC instruction caused by a program for
subtracting "1"
"1" is subtracted from the contents of D0 every time X001 turns ON from OFF.
SUB instruction is similar to DECP instruction described later except the contents shown in the table below.
SUB/SUBP/DSUB/DSUBP
instructions
DEC/DECP/DDEC/DDECP instructions
Flag (zero, borrow, carry) Operates Does not operate
Operation result
16-bit
operation
-(+1)=
← -2 ← -1 ← 0 ← -32,768 -32,768 → +32,767 → +32,766
-(-1)=
+32,767 → 0 → +1 → +2 → -
32-bit
operation
-(+1)=
← -2 ← -1 ←0 ← -2,147,483,648 -2,147,483,648 → +2,147,483,647 → +2,147,483,646
-(-1)=
+2,147,483,647 → 0 → +1 → +2 → -
(D 0) – 1 → (D 0)
X001
D0
D0
SUBP
EN
s1
s2
ENO
d
K1
DECP
EN ENO
d
X001
D0
[
Structured ladder
][ ST ]
SUBP(X001, D0, K1, D0);
DECP(X001, D0);
(D 0) – 1 → (D 0)