The implementation is based on the following equation:
Notes of the above equation:
- 2'sComp stands for 2's complement
- Also we know that 2'sComp = 1'sComp + 1
So to design a single HW that implements both add and subtract operation, you can use a adder unit (ripple adder) with following consideration
- Assuming the inputs of adder are Ai and Bi
- you need to put a Mux2x1 behind the Bi input and pass Bi and Bi' as inputs of this Mux2x1
- The selector of all Mux2x1 components is a control signal which decides you want to do add or subtract operation (lets call it SUB).
- Assuming SUB=1 we want to do subtract operation, in MUX make sure Bi'is connected to I1 of Mux2x1 and Bi is connected to I0 of Mux2x1
- We also connect the SUB to Cin of LSB full adder component in ripple adder