Sub (subtraction) – KEYENCE Visual KV Series User Manual

Page 177

Advertising
background image

2.4 Instruction Details

1

2

3-153

Chapter 2 Instructions

SUB (Subtraction)

Coding

Description

•

The SUB instruction subtracts the operand value from the contents of the internal
register and inputs the result back into the internal register.

•

In the above example, "#00100" is subtracted from the contents of DM0000 and
the result is stored in DM0001.

•

When the contents of DM0000 is "#00150", for example, "#00050" is stored in
DM0001.
DM0000 (#00150) – #00100

➞ DM0001 (#00050)

Note 1: When the operation result is a negative value (-), the 2's complement value
is also stored in the internal register.
Special utility relay 2009 turns ON.

Note 2: To convert the complement into an antilogarithm, add the following opera-
tion:

Inverted bit of complement + 1 = Antilogarithm

Tips

Solution when operation result is a negative value

When DM0000 is "#10" and DM0001 is "#30", "#20" is stored in DM0003.

Arithmetic flag

2009

Turns ON when the result of a SUB operation is negative. Turns OFF at
other times.

2010

Turns ON when the contents of the internal register is "0" after a SUB
operation. Turns OFF at other times.

2011

Turns ON when the result of a SUB operation is positive. Turns OFF at other
times.

2012

The DM or relay indirectly addressed with #TM is out of range.

➮ "Indirect addressing" (p. 3-127)

DM0000

LDA

#00100

SUB

DM0001

STA

2002

Line No.

Instruction

Operand

0000

LD

2002

0001

LDA

DM0000

0002

CON

0003

SUB

#00100

0004

CON

0005

STA

DM0001

0

1

= $0001

0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

1

-

= $FFFF

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

0

= $0002

0 0 0 0 0 0 0 0 0 0 0 0 0 1 0

2009

2's complement is stored.

Internal register

Operand

Underflow

DM0000

LDA

DM0001

SUB

DM0002

STA

COM

#0001

ADD

DM0003

STA

2002

2009

2009

DM0000 - DM0001 =

(Stores positive value)

(Stores negative value)

Absolute value
is stored.

Positive value

DM0002

Negative value

DM0003

SUB / @SUB

KVNKA Chap 02_4cP.p65

08.3.11, 0:02 PM

153

Advertising