5 Categories and Use of Basic Application Instructions API 29 Operands: D : Device to store the operation result of 2’s Compliment Explanations: 1. NEG instruction conducts operation of 2’s complement and can be used for converting a negative BIN value into an absolute value 2. When NEG is used as 16-bit instruction, Z device cannot be adopted; when NEG is used as 32-bit instruction, V device cannot be adopted. 3. This instruction is generally used in pulse execution mode (NEGP, DNEGP). Program Example 1: When X0 goes from OFF to ON, the phase of each bit in D10 will be reversed (0 → 1, 1 → 0) and then 1 will be added to the Least Significant Bit (LSB) of the register.
Operation result will then be stored in D10. Program Example 2: To obtain the absolute value of a negative value: 1. When MSB (b15) of D0 is “1”, M0 = ON. (D0 is a negative value) 2. When M0 = ON, the absolute value of D0 can be obtained by NEG instruction. M1000 K15 M0 Program Example 3: Obtain the absolute value of the remainder of the subtraction. When X0 = ON, 1. If D0 > D2, M0 = ON. 2. If D0 = D2, M1 = ON. 3. If D0 4. D4 is then able to remain positive. DVP-PM Operation Instruction 5-46 Mnemonic Operands Function Controllers 20PM 10PM D NEG P 2’s Complement (Negation) Type OP Bit Devices Word Devices Program Steps X Y M S K H KnX KnY KnM KnS T C D V Z NEG, NEGP: 7 steps DNEG, DNEGP:
9 steps D * * * * * * * * D X 0 NEGP D10 BON D0 M0 NEGP D0 X 0 CMP D0 D2 M0 SUB D0 D2 D4 SUB D2 D0 D4