Chapter 11 Math Instructions

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 42

Chapter 11

© 2011, The McGraw-Hill Companies, Inc.


11.1

Math Instructions

© 2011, The McGraw-Hill Companies, Inc.


The PLC’s math functions capability allows it
to perform arithmetic functions on values.

Addition - The capability to add one piece of data to


another.
Subtraction - The capability to subtract one piece of
data from another.
Multiplication - The capability to multiply one piece
of data by another.
Division - The capability to divide one piece of data
by another.
© 2011, The McGraw-Hill Companies, Inc.
When the CPT (compute)
instruction is executed, then
copy, arithmetic, logical, or
conversion operation residing
in the expression field of this
instruction is performed and
the result is sent to the
destination.

© 2011, The McGraw-Hill Companies, Inc.


11.2

Addition Instruction

© 2011, The McGraw-Hill Companies, Inc.


The ADD instruction performs the addition of
two values stored in the referenced memory
locations.

© 2011, The McGraw-Hill Companies, Inc.


Simulated ADD instruction rung.

© 2011, The McGraw-Hill Companies, Inc.


Counter program that uses the ADD instruction.

© 2011, The McGraw-Hill Companies, Inc.


Simulated counter program.

© 2011, The McGraw-Hill Companies, Inc.


The arithmetic status
bits for the SLC 500
are found in word 0,
bits 0 to 3 of the
processor status file S2.
Carry (C) - Address S2:0/0, is set to 1 when there is
a carry in the ADD instruction or a borrow in the SUB
instruction.
Overflow (O) -Address S2:0/1, is set to 1 when the
result is too large to fit in the destination register.
Zero (Z) - Address S2:0/2, is set to 1 when the result
of the subtract instruction is zero.
Sign (S) - Address S2:0/3, is set to 1 when the result
is a negative number.
© 2011, The McGraw-Hill Companies, Inc.
11.3

Subtraction Instruction

© 2011, The McGraw-Hill Companies, Inc.


The subtract instruction subtracts source B from
source A and stores the result in the destination.

© 2011, The McGraw-Hill Companies, Inc.


Simulated SUB instruction rung.

© 2011, The McGraw-Hill Companies, Inc.


Vessel overfill alarm program.

© 2011, The McGraw-Hill Companies, Inc.


Simulated vessel overfill alarm program.

© 2011, The McGraw-Hill Companies, Inc.


11.4

Multiplication Instruction

© 2011, The McGraw-Hill Companies, Inc.


The multiply instruction multiplies two values and
stores the result in the destination address.

© 2011, The McGraw-Hill Companies, Inc.


Simulated MUL instruction rung.

© 2011, The McGraw-Hill Companies, Inc.


MUL instruction program used to calculate
the product of two sources.

© 2011, The McGraw-Hill Companies, Inc.


Simulated MUL instruction program used to
calculate the product of two sources.

© 2011, The McGraw-Hill Companies, Inc.


The MUL
instruction
used as part
of a
temperature
control
program.

© 2011, The McGraw-Hill Companies, Inc.


11.5

Division Instruction

© 2011, The McGraw-Hill Companies, Inc.


The division instruction divides the value in
source A by the value in source B and stores the
result in the destination address.

© 2011, The McGraw-Hill Companies, Inc.


Simulated DIV instruction rung.

© 2011, The McGraw-Hill Companies, Inc.


DIV instruction used to calculate the value that
results from dividing source A by source B.

© 2011, The McGraw-Hill Companies, Inc.


Simulated DIV instruction program.

© 2011, The McGraw-Hill Companies, Inc.


Program for
converting
Celsius
temperature to
Fahrenheit.

© 2011, The McGraw-Hill Companies, Inc.


11.6

Other Word-Level Math


Instructions
© 2011, The McGraw-Hill Companies, Inc.
Square root instruction.

© 2011, The McGraw-Hill Companies, Inc.


Simulated square root instruction rung.

© 2011, The McGraw-Hill Companies, Inc.


The negate (NEG) instruction changes the sign of
the source value from positive to negative.

© 2011, The McGraw-Hill Companies, Inc.


Simulated negate instruction rung.

© 2011, The McGraw-Hill Companies, Inc.


The clear (CLR) instruction sets all bits of a word
to zero.

© 2011, The McGraw-Hill Companies, Inc.


Simulated clear instruction rung.

© 2011, The McGraw-Hill Companies, Inc.


The convert to BCD (TOD) instruction is used to
convert 16-bit integers into binary-coded decimal
(BCD) values.

© 2011, The McGraw-Hill Companies, Inc.


Simulated convert to BCD (TOD) instruction rung.

© 2011, The McGraw-Hill Companies, Inc.


The scale data (SCL) instruction is used to allow
very large or very small numbers to be enlarged
or reduced by the rate value.

The number 100


stored at the source
address, N7:0, is
multiplied by 25,000,
divided by 10,000,
and added to 127.

The result, 377, is placed in the destination


address, N7:1.
© 2011, The McGraw-Hill Companies, Inc.
11.7

File Arithmetic
Operations
© 2011, The McGraw-Hill Companies, Inc.
The file arithmetic and logic (FAL) instruction
can combine an arithmetic operation with file
transfer.

The file add


function of the
FAL instruction is
used to perform
addition
operations on
multiple words.

© 2011, The McGraw-Hill Companies, Inc.


The file subtract function of the FAL
instruction is used to perform subtraction
operations on multiple words.

© 2011, The McGraw-Hill Companies, Inc.


The file multiplication function of the FAL
instruction is used to perform multiplication
operations on multiple words.

© 2011, The McGraw-Hill Companies, Inc.


The file divide function of the FAL
instruction is used to perform division
operations on multiple words.

© 2011, The McGraw-Hill Companies, Inc.

You might also like