Carry And Borrow In Addition/Subtraction - FATEK FBS Series Manual

Plc
Hide thumbs Also See for FBS Series:
Table of Contents

Advertisement

Increase
(Decrease)
Overflow/
Underflow
Increase
Decrease
5.5

Carry and Borrow in Addition/Subtraction

Overflow/Underflow takes place when the operation of increment/decrement causes the value of the operand to exceed
the positive/negative limit that can be represented in the PLC, consequently a flag of overflow/underflow is introduced.
Carry/Borrow flag is different from overflow/underflow. At first, there must be two operands making addition (subtraction)
where a sum (difference) and a flag of carry/borrow will be obtained. Since the number of bits of the numbers to be added
(subtracted), to add (subtract) and of sum (difference) are the same (either 16-bit or 32-bit), the result of addition
(subtraction) may cause the value of sum (difference) to exceed 16-bit or 32-bit. Therefore, it is necessary to use
carry/borrow flag to be in coordination with the sum (difference) operand to represent the actual value. The carry flag is
set when the addition (subtraction) result exceeds the positive limit (32767 or 2147483647) of the sum (difference)
operand. The borrow flag is set when addition (subtraction) result exceeds the negative limit (−32768 or −2147483648)
of the sum (difference) operand. Hence, the actual result after addition (subtraction) is equal to the carry/borrow plus the
value of the sum (difference) operand. The FO of FBs-PLC addition/subtraction instruction has both carry and borrow flag
outputs for obtaining the actual result.
+(−)
1-bit
While all FBs-PLC numerical operations use 2'S Complement, the representation of the negative value of the sum
Result
16-bit Operand
OVF=1
UDF=1
MSB
Carry/Borrow
−32767
−32768
32767
32766
32765
−32767
−32768
32767
32766
32765
LSB
16-bit/32-bit
16-bit/32-bit
16-bit or 32-bit
5 - 13
32-bit Operand
−2147483646
−2147483647
OVF=1
−2147483648
2147483647
2147483646
−2147483647
−2147483648
UDF=1
2147483647
2147483646
2147483645
To Be Added (Subtracted) Operand
Addition (Subtraction) Operand
Sum (Difference) Operand

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents