Bit addition and subtraction, Math overflow selection bit s2/14, Example of 32-bit addition – Rockwell Automation 1761-HHP-B30 MicroLogix 1000 with Hand-Held Programmer (HHP) User Manual

Page 172

Advertising
background image

Chapter 10
Using Math Instructions

10–6

You have the option of performing 16-bit or 32-bit signed integer addition
and subtraction. This is facilitated by status file bit S2/14 (math overflow
selection bit).

Math Overflow Selection Bit S2/14

Set this bit when you intend to use 32-bit addition and subtraction. When
S2/14 is set, and the result of an ADD, SUB, MUL, DIV, or NEG instruction
cannot be represented in the destination address (due to math underflow or
overflow):

The overflow bit S0/1 is set.

The overflow trap bit S5/0 is set.

The destination address contains the unsigned truncated least significant
16 bits of the result.

When S2/14 is reset (default condition), and the result of an ADD, SUB,
MUL, DIV, or NEG instruction cannot be represented in the destination
address (due to math underflow or overflow):

The overflow bit S0/1 is set.

The overflow trap bit S5/0 is set.

The destination address contains 32767 if the result is positive or –32768
if the result is negative.

Note that the status of bit S2/14 has no effect on the DDV instruction. Also,
it has no effect on the math register content when using MUL and DIV
instructions.

Example of 32-bit Addition

The following example shows how a 16-bit signed integer is added to a
32-bit signed integer. Remember that S2/14 must be set for 32-bit addition.

Note that the value of the most significant 16 bits (B3) of the 32-bit number
is increased by 1 if the carry bit S0/0 is set and is decreased by 1 if the
number being added (B1) is negative.

To avoid a major error from occurring at the end of the scan, you must
unlatch overflow trap bit S5/0 as shown.

Add 16–bit value B1 to 32–bit value B3 B2

Add Operation

Binary

Hex

Decimal

B3 B2

B1

B3 B2

0000 0000 0000 0011 0001 1001 0100 0000

0101 0101 1010 1000

0000 0000 0000 0011 0110 1110 1110 1000

0003 1940

55A8

0003 6EE8

203,072

21,928

225,000

Addend
Addend

Sum

The programming device displays 16-bit decimal values only. The decimal value of a 32-bit integer is derived from the displayed
binary or hex value. For example, 0003 1940 Hex is 16

4

x3 + 16

3

x1 + 16

2

x9 + 16

1

x4 + 16

0

x0 = 203,072.

32-Bit Addition and
Subtraction

Advertising