
Altera Corporation
 17
Arithmetic Functions
lpm_add_sub
Parameterized Adder/ Subtractor 
Ports
 Name
Type
Required
Description
add_sub
Input
No
If the input is high, the operation = 
dataa[]
+
datab[]
. If the input is low, 
the operation = 
dataa[]
–
datab[]
. This port cannot be used if the 
LPM_DIRECTION
 parameter is used. If both the 
add_sub
 port and the 
LPM_DIRECTION
 parameter are omitted, the operation defaults to 
"ADD"
.
Carry-in to the low-order bit. If the operation is 
"ADD"
, Low = 0 and High = +1. 
If the operation is 
"SUB"
, Low = –1 and High = 0. If omitted, the default is 0 
(i.e., no affect on 
"ADD"
 or 
"SUB"
 operations).
Augend/Minuend. This port is 
LPM_WIDTH
 wide.
Clock for pipelined usage. The 
clock
 port provides pipelined operation of 
lpm_add_sub
. For 
LPM_PIPELINE
 values other than 0 (default value), the 
clock
 port must be connected.
Addend/Subtrahend. This port is 
LPM_WIDTH
 wide.
Asynchronous clear for pipelined usage. The pipeline initializes to undefined. 
The 
aclr
 port can be used at any time to reset the pipeline to all 0s, 
asynchronously to 
clock
.
dataa[]
 + or – 
datab[]
 + or – 
cin
. This port is 
LPM_WIDTH
 wide.
Result exceeds available precision. If 
overflow
 is used, 
cout
 cannot be 
used. The 
overflow
 signal has a physical interpretation as the 
XOR
 of the 
carry into the MSB with the carry out of the MSB. The 
overflow
 signal is only 
meaningful when the 
LPM_REPRESENTATION
 parameter is set to 
"SIGNED"
.
Note (1)
Carry-out (borrow-in) of the MSB. If 
overflow
 is used, 
cout
 cannot be used. 
The 
cout
 signal has a physical interpretation as the carry-out (borrow-in)
of the MSB and is most meaningful for detecting overflow in 
"UNSIGNED"
operations. 
Note (2)
cin
Input
No
dataa[]
Input
Input
Yes
No
clock
datab[]
Input
Input
Yes
No
aclr
result[]
Output
Output
Yes
No
overflow
cout
Output
No
cin
result[]
dataa[]
clock
datab[]
cout
LPM_ADD_SUB
LPM_DIRECTION=
LPM_PIPELINE=
LPM_REPRESENTATION=
LPM_WIDTH=
ONE_INPUT_IS_CONSTANT=
add_sub
overflow
aclr