## ABSTRACT

Numerical data imply the ability to do arithmetical operations, and almost all PLCs provide some arithmetical operations such as add, subtract, multiply, and divide. Arithmetical functions will retrieve one or more values, perform an operation, and store the result in memory. The following arithmetical macros are described in this chapter: R1addR2 (R1 + R2) (add the contents of two 8-bit registers), R1addR2_16 (R1 + R2_16) (add the contents of two 16-bit registers), RaddK (R + K) (add the content of an 8-bit register (R) and an 8-bit constant (K)), RaddK_16 (R + K_16) (add the content of a 16-bit register (R) and a 16-bit constant (K)), R1subR2 (R1 - R2) (subtract the content of the 8-bit register R2 from the content of the 8-bit register R1), R1subR2_16 (R1 - R2_16) (subtract the content of the 16- bit register R2 from the content of the 16-bit register R1), RsubK (R - K) (subtract the 8-bit constant value K from the content of the 8-bit register R), RsubK_16 (R - K_16) (subtract the 16-bit constant value K from the content of the 16-bit register R), R1mulR2 (R1 × R2) (multiply the contents of two 8-bit registers), DivU16by8 (R1_16 / R2_8) (divide the content of the 16-bit register R1 by the content of the 8-bit register R2), incR (IN + 1) (increment the content of the 8-bit register IN), incR_16 (IN + 1_16) (increment the content of the 16-bit register IN), decR (IN – 1) (decrement the content of the 8-bit register IN), decR_16 (IN – 1_16) (decrement the content of the 16-bit register IN), Hbit_CNT (High Bit Counter), Lbit_CNT (Low Bit Counter). Nine examples are considered to show the application of arithmetical macros presented in this chapter.