Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 29 of 68

Programmable Controllers C200HX-CPU-ZE, C200HG-CPU-ZE, C200HE-CPU-ZE Operation Manual: SECTION 5 Instruction Set, pages 254 to 263

Pages 254 to 263 of 613, from Programmable Controllers C200HX-CPU-ZE, C200HG-CPU-ZE, C200HE-CPU-ZE Operation Manual

The original document is the PDF (3.8 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

Filed in the catalog under the Omron C200H-SP001 and Omron C200HW-PA204

Page 254

Section 5-18

Data Conversion

5-18-15 2’S COMPLEMENT – NEG(160)

Ladder Symbols

Operand Data Areas

NEG(160)

@NEG(160)

S: Source word

S

S

IR, SR, AR, DM, EM, HR, TC, LR, #

R

R

R: Result word IR, SR, AR, DM, EM, HR, LR

Limitations

NEG(160) is an expansion instruction. A Programming Device can be used to reassign function code 160 to another expansion instruction.

Description

Converts the four-digit hexadecimal content of the source word (S) to its 2’s complement and outputs the result to the result word (R). This operation is effectively the same as subtracting S from 0000 and outputting the result to R. If the content of S is 0000, the content of R will also be 0000 after execution, and EQ (SR 25506) will be turned ON. If the content of S is 8000, the content of R will also be 8000 after execution, and UF (SR 25405) will be turned ON. Note Refer to page 30 for details on 16-bit signed binary data.

Flags

Example

ER:

The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.

EQ:

ON when the content of S is 0000; otherwise OFF.

UF:

ON when the content of S is 8000; otherwise OFF.

N:

ON when bit 15 of R is set to 1; otherwise OFF.

The following example shows how to use NEG(160) to find the 2’s complement of the hexadecimal value 001F and output the result to DM 0020. 00000 NEG(160) #001F DM 0020

Address

Instruction

00000 00001

LD NEG(160)

#0000 #001F

#FFE1

242

00000 #001F DM 0020

---

–

Operands

Output to DM 0020.

Page 255

Section 5-18

Data Conversion

5-18-16 DOUBLE 2’S COMPLEMENT – NEGL(161) Ladder Symbols

Limitations

Operand Data Areas

NEGL(161)

@NEGL(161)

S: First source word

S

S

IR, SR, AR, DM, EM, HR, TC, LR

R

R

R: First result word

---

---

IR, SR, AR, DM, EM, HR, LR

S and S+1 must be in the same data area, as must R and R+1. NEGL(161) is an expansion instruction. A Programming Device can be used to reassign function code 161 to another expansion instruction.

Description

Converts the eight-digit hexadecimal content of the source words (S and S+1) to its 2’s complement and outputs the result to the result words (R and R+1). This operation is effectively the same as subtracting the eight-digit content S and S+1 from $0000 0000 and outputting the result to R and R+1. If the content of S is 0000 0000, the content of R will also be 0000 0000 after execution and EQ (SR 25506) will be turned ON. If the content of S is 8000 0000, the content of R will also be 8000 0000 after execution and UF (SR 25405) will be turned ON. Note Refer to page 30 for details on 32-bit signed binary data.

Flags

Example

ER:

The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.

EQ:

ON when the content of S+1, S is 0000 0000; otherwise OFF.

UF:

ON when the content of S+1, S is 8000 0000; otherwise OFF.

N:

ON when bit 15 of R+1 is set to 1; otherwise OFF.

The following example shows how to use NEGL(161) to find the 2’s complement of the hexadecimal value in LR 21, LR 20 (001F FFFF) and output the result to DM 0021, DM 0020. 00000 NEGL(161) LR20 DM 0020

Address

Instruction

00000 00001

LD NEGL(161)

00000 LR 20 DM 0020

---

0000 S+1: LR 21

–

Operands

001F R+1: DM 0021 FFE0

0000 S: LR 20 FFFF R: DM 0020 0001

243

Page 256

Section 5-19

Symbol Math Instructions

5-19 Symbol Math Instructions The Symbol Math Instructions perform arithmetic operations on BCD, binary, or floating-point data.

5-19-1 Binary Addition: +(400)/+L(401)/+C(402)/+CL(403) SIGNED BINARY ADD WITHOUT CARRY: +(400) Ladder Symbols

Operand Data Areas

+(400)

@+(400)

Au

Au

Ad

Ad

R

R

Au: Augend word IR, SR, AR, DM, EM, HR, TC, LR, # Ad: Addend word IR, SR, AR, DM, EM, HR, TC, LR, # R: Result word IR, SR, AR, DM, EM, HR, LR

DOUBLE SIGNED BINARY ADD WITHOUT CARRY: +L(401) Ladder Symbols

Operand Data Areas

+L(401)

@+L(401)

Au

Au

Ad

Ad

R

R

Au: 1st augend word IR, SR, AR, DM, EM, HR, TC, LR Ad: 1st addend word IR, SR, AR, DM, EM, HR, TC, LR R: 1st result word IR, SR, AR, DM, EM, HR, LR

SIGNED BINARY ADD WITH CARRY: +C(402) Ladder Symbols

Operand Data Areas

+C(402)

@+C(402)

Au

Au

Ad

Ad

R

R

Au: Augend word IR, SR, AR, DM, EM, HR, TC, LR, # Ad: Addend word IR, SR, AR, DM, EM, HR, TC, LR, # R: Result word IR, SR, AR, DM, EM, HR, LR

DOUBLE SIGNED BINARY ADD WITH CARRY: +CL(403) Ladder Symbols

Operand Data Areas

+CL(403)

@+CL(403)

Au

Au

Ad

Ad

R

R

Au: 1st augend word IR, SR, AR, DM, EM, HR, TC, LR Ad: 1st addend word IR, SR, AR, DM, EM, HR, TC, LR R: 1st result word IR, SR, AR, DM, EM, HR, LR

244

Page 257

Section 5-19

Symbol Math Instructions Description

SIGNED BINARY ADD WITHOUT CARRY When the execution condition is OFF, +(400) is not executed. When the execution condition is ON, +(400) adds the contents of Au and Ad and places the result in R. CY will be set if the result is greater than FFFF. Au +

Ad

CY

R

DOUBLE SIGNED BINARY ADD WITHOUT CARRY When the execution condition is OFF, +L(401) is not executed. When the execution condition is ON, +L(401) adds the 8-digit contents of Au+1 and Au and the 8-digit contents of Ad+1 and Ad, and places the result in R and R + 1. CY will be set if the result is greater than FFFF FFFF. Au +1

Au

+

Ad + 1

Ad

CY

R+1

R

SIGNED BINARY ADD WITH CARRY When the execution condition is OFF, +C(402) is not executed. When the execution condition is ON, +C(402) adds the contents of Au, Ad, and CY and places the result in R. CY will be set if the result is greater than FFFF. Au Ad CY

+ CY

R

DOUBLE SIGNED BINARY ADD WITH CARRY When the execution condition is OFF, +CL(403) is not executed. When the execution condition is ON, +CL(403) adds the 8-digit contents of Au+1, Au, the 8-digit contents of Ad+1 and Ad, and CY, and places the result in R and R + 1. CY will be set if the result is greater than FFFF FFFF. Au +1

Au

Ad + 1

Ad CY

+ CY

Flags

R+1

R

ER:

The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.

CY:

The result is greater than FFFF or FFFF FFFF.

EQ:

The result is 0.

OF:

Au (Au +1) and Ad (Ad +1) are both positive numbers and the result is negative.

UF:

Au (Au +1) and Ad (Ad +1) are both negative numbers and the result is positive.

245

Page 258

Section 5-19

Symbol Math Instructions N:

Shows the status of bit 15 of R or R+1.

Using Signed Binary Addition Instructions The range for signed data is –32,768 to 32,767 in decimal (–2,147,483,648 to 2,147,483,647 for “double” instructions), and 8000 to FFFF and 0000 to 7FFF in hexadecimal (8000 0000 to FFFF FFFF and 0000 0000 to 7FFF FFFF for “double” instructions). Negative numbers are expressed as 2’s complements. If the result of the addition is within the range of 8000 to FFFF, it represents a signed negative number and the Negative Flag (SR 25402) turns ON. When Au and Ad are both positive numbers and the addition result is negative, the Overflow Flag (SR 25404) turns ON. When Au and Ad are both negative numbers and the addition result is positive, the Underflow Flag (SR 25405) turns ON. If a addition result in a carry, the Carry Flag turns ON. The range for unsigned binary data is 0000 to FFFF (0000 0000 to FFFF FFFF for “double” instructions), so the decimal range would be 0 to 65,535 (0 to 4,294,967,295).

5-19-2 BCD Addition: +B(404)/ +BL(405)/+BC(406)/+BCL(407) BCD ADD WITHOUT CARRY: +B(404) Ladder Symbols

Operand Data Areas

+B(404)

@+B(404)

Au

Au

Ad

Ad

R

R

Au: Augend word IR, SR, AR, DM, EM, HR, TC, LR, # Ad: Addend word IR, SR, AR, DM, EM, HR, TC, LR, # R: Result word IR, SR, AR, DM, EM, HR, LR

DOUBLE BCD ADD WITHOUT CARRY: +BL(405) Ladder Symbols

Operand Data Areas

+BL(405)

@+BL(405)

Au

Au

Ad

Ad

R

R

Au: 1st augend word IR, SR, AR, DM, EM, HR, TC, LR Ad: 1st addend word IR, SR, AR, DM, EM, HR, TC, LR R: 1st result word IR, SR, AR, DM, EM, HR, LR

BCD ADD WITH CARRY: +BC(406) Ladder Symbols

Operand Data Areas

+BC(406)

@+BC(406)

Au

Au

Ad

Ad

R

R

Au: Augend word IR, SR, AR, DM, EM, HR, TC, LR, # Ad: Addend word IR, SR, AR, DM, EM, HR, TC, LR, # R: Result word IR, SR, AR, DM, EM, HR, LR

246

Page 259

Section 5-19

Symbol Math Instructions DOUBLE BCD ADD WITH CARRY: +BCL(407) Ladder Symbols

Operand Data Areas

+BCL(407)

@+BCL(407)

Au

Au

Ad

Ad

R

R

Au: 1st augend word IR, SR, AR, DM, EM, HR, TC, LR Ad: 1st addend word IR, SR, AR, DM, EM, HR, TC, LR R: 1st result word IR, SR, AR, DM, EM, HR, LR

Description

BCD ADD WITHOUT CARRY When the execution condition is OFF, +B(404) is not executed. When the execution condition is ON, +B(404) adds the contents of Au and Ad and places the result in R. CY will be set if the result is greater than 9999. Au +

Ad

CY

R

DOUBLE BCD ADD WITHOUT CARRY When the execution condition is OFF, +BL(405) is not executed. When the execution condition is ON, +BL(405) adds the 8-digit contents of Au+1 and Au and the 8-digit contents of Ad+1 and Ad, and places the result in R and R + 1. CY will be set if the result is greater than 9999 9999. Au +1

Au

+

Ad + 1

Ad

CY

R+1

R

BCD ADD WITH CARRY When the execution condition is OFF, +BC(406) is not executed. When the execution condition is ON, +BC(406) adds the contents of Au, Ad, and CY and places the result in R. CY will be set if the result is greater than 9999. Au Ad CY

+ CY

R

DOUBLE BCD ADD WITH CARRY When the execution condition is OFF, +BCL(407) is not executed. When the execution condition is ON, +BCL(407) adds the 8-digit contents of Au+1, Au, the 8-digit contents of Ad+1 and Ad, and CY, and places the result in R and R + 1. CY will be set if the result is greater than 9999 9999.

247

Page 260

Section 5-19

Symbol Math Instructions Au +1

Au

Ad + 1

Ad CY

+ CY

R+1

R

Precautions

Au and Ad (or Au, Au+1, Ad, and Ad+1) must be BCD. If any other data is used, the Error Flag (SR 25503) will turn ON and the instruction will not be executed.

Flags

ER:

Au and Ad (or Au, Au+1, Ad, and Ad+1) are not BCD. The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.

Example

CY:

The result exceeds the digits.

EQ:

The result after the addition is all zeros.

+BL Operation When IR 00000 is ON in the following example, the contents of DM 0101 and DM 0100 are added to the content of DM 0111 and DM 0110, and the result is output in eight-digit BCD to DM 0121 and DM 0120. +BCL Operation When IR 00001 is ON in the following example, the contents of DM 0201 and DM 0200 are added to the content of DM 0211 and DM 0210, and the result including the carry is output in eight-digit BCD to DM 0221 and DM 0220.

00000

Address

Instruction

DM 0100

00000

LD

DM 0110

00001

+BL(405)

+BL(405)

Operands 00000 DM 0100

DM 0120

DM 0110 00001

DM 0120

+BCL(407) DM 0200

00002

LD

DM 0210

00003

+BCL(407)

00001 DM 0200

DM 0220

DM 0210 DM 0220

5-19-3 Binary Subtraction: –(410)/ –L(411)/–C(412)/–CL(413) SIGNED BINARY SUBTRACT WITHOUT CARRY: –(410) Ladder Symbols

Operand Data Areas Mi: Minuend word

–(410)

@–(410)

Mi

Mi

Su

Su

R

R

IR, SR, AR, DM, EM, HR, TC, LR, # Su: Subtrahend word IR, SR, AR, DM, EM, HR, TC, LR, # R: Result word IR, SR, AR, DM, EM, HR, LR

248

Page 261

Section 5-19

Symbol Math Instructions DOUBLE SIGNED BINARY SUBTRACT WITHOUT CARRY: –L(411) Ladder Symbols

Operand Data Areas Mi: 1st minuend word

–L(411)

@–L(411)

Mi

Mi

Su

Su

R

R

IR, SR, AR, DM, EM, HR, TC, LR Su: 1st subtrahend word IR, SR, AR, DM, EM, HR, TC, LR R: 1st result word IR, SR, AR, DM, EM, HR, LR

SIGNED BINARY SUBTRACT WITH CARRY: –C(412) Ladder Symbols

Operand Data Areas Mi: Minuend word

–C(412)

@–C(412)

Mi

Mi

Su

Su

R

R

IR, SR, AR, DM, EM, HR, TC, LR, # Su: Subtrahend word IR, SR, AR, DM, EM, HR, TC, LR, # R: Result word IR, SR, AR, DM, EM, HR, LR

DOUBLE SIGNED BINARY SUBTRACT WITH CARRY: –CL(413) Ladder Symbols

Operand Data Areas Mi: 1st minuend word

–CL(413)

@–CL(413)

Mi

Mi

Su

Su

R

R

IR, SR, AR, DM, EM, HR, TC, LR Su: 1st subtrahend word IR, SR, AR, DM, EM, HR, TC, LR R: 1st result word IR, SR, AR, DM, EM, HR, LR

Description

SIGNED BINARY SUBTRACT WITHOUT CARRY When the execution condition is OFF, –(410) is not executed. When the execution condition is ON, –(410) subtracts the contents of Su from Mi and places the result in R. If the subtraction resulted in a borrow, CY is set. To obtain the true answer when the result is negative, the 2’s complement placed in R must be subtracted from 0000.

Mi

– Su

CY

R

249

Page 262

Section 5-19

Symbol Math Instructions

DOUBLE SIGNED BINARY SUBTRACT WITHOUT CARRY When the execution condition is OFF, –L(411) is not executed. When the execution condition is ON, –L(411) subtracts the 8-digit value in Su and Su+1 from the 8-digit value in Mi and Mi+1, and places the result in R and R+1. If the subtraction resulted in a borrow, CY is set. Mi + 1

Mi

–

Su + 1

Su

CY

R+1

R

SIGNED BINARY SUBTRACT WITH CARRY When the execution condition is OFF, –C(412) is not executed. When the execution condition is ON, –C(412) subtracts the contents of Su and CY from Mi and places the result in R. If the subtraction resulted in a borrow, CY is set. Mi

–

Su

–

CY

CY

R

DOUBLE SIGNED BINARY SUBTRACT WITH CARRY When the execution condition is OFF, –CL(413) is not executed. When the execution condition is ON, –CL(413) subtracts CY and the 8-digit value in Su and Su+1 from the 8-digit value in Mi and Mi+1, and places the result in R and R+1. If the subtraction resulted in a borrow, CY is set. Mi + 1

Mi

Su + 1

Su

– CY

Flags

CY R+1

R

ER:

The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.

CY:

The subtraction resulted in a carry.

EQ:

The contents of word R (or word R and R+1 for “double” instructions) after the subtraction is all zeros

OF:

Mi is a positive number, Su is negative, and the subtraction result is negative.

UF:

Mi is a negative number, Su is positive, and the subtraction result is positive.

N:

The leftmost bit (MSB) of word R (or word R+1 for “double” instructions) after the subtraction is “1.”

Using SIGNED BINARY SUBTRACT Instructions The range for signed data is –32,768 to 32,767 in decimal (–2,147,483,648 to 2,147,483,647 for “double” instructions), and 8000 to FFFF and 0000 to 7FFF in hexadecimal (8000 0000 to FFFF FFFF and 0000 0000 to 7FFF FFFF for “double” instructions). Negative numbers are expressed as 2’s complements. If the result of the subtraction is within the range of 8000 to FFFF, it represents a signed negative number and the Negative Flag (SR 25402) turns ON.

250

Page 263

Section 5-19

Symbol Math Instructions

When Mi is a positive number, Su is negative and the subtraction result is negative, the Overflow Flag (SR 25404) turns ON. When Mi is a negative number, Su is positive, and the subtraction result is positive, the Underflow Flag (SR 25405) turns ON. If a subtraction result in a borrow, the Carry Flag turns ON. The range for unsigned binary data is 0000 to FFFF (0000 0000 to FFFF FFFF for “double” instructions), so the decimal range would be 0 to 65,535 (0 to 4,294,967,295). When data is unsigned, the Carry Flag turning ON indicates that the subtraction result is negative. The result is expressed as 2’s complement, so in order to find the true answer, the 2’s complement must be subtracted from 0. Numeric Example 1 Signed data –)

FFFFH 0001H

–)

FFFEH

Unsigned data

–1 +1

–)

–2 (Note 1)

65535 1 65534 (Note 2)

Negative Flag ON Carry Flag OFF

Numeric Example 2 Signed data –)

FFFDH FFFFH FFFEH

–)

–3 –1 –2 (Note 1)

Unsigned data –)

65533 65535 –2 (Note 3)

Negative Flag ON Carry Flag ON

Note

1. Because the Negative Flag is ON, the result (FFFE) is a negative number (2’s complement) and is expressed as –2. 2. The Carry Flag is OFF and the result (FFFE) is an unsigned positive number (65,534). 3. The Carry Flag is ON so the result (FFFE) is an unsigned negative number (2’s complement) and becomes –2 when converted.

Programming Example 1

–L Operation When IR 00000 is ON in the following example, the content of DM 0111 and DM 0110 is subtracted from the content of DM 0101 and DM 0100, and the result is output in eight-digit binary to DM 0121 and DM 0120. CY is set if the subtraction resulted in a borrow. –CL Operation When IR 00001 is ON in the following example, the content of DM 0211 and DM 0210 is subtracted from the content of DM 0201 and DM 0200, and the result is output in eight-digit binary to DM 0221 and DM 0220. CY is set if the subtraction resulted in a borrow.

251