Adder-subtractor¶
What is adder-subtractor?¶
An adder-subtractor can be built from an adder by optionally negating one of the inputs, which is equivalent to inverting the input then adding 1. The net result is a circuit that can do two operations: (a + b + 0) and (a + ~b + 1). See Wikipedia if you want a more detailed explanation of how this circuit works.
Problem statement¶
Build the adder-subtractor below.
You are provided with a 16-bit adder module, which you need to instantiate twice:
Verilog Use a 32-bit wide XOR gate to invert the
b
input wheneversub
is 1. (This can also be viewed asb[31:0]
XORed with sub replicated 32 times. See replication operator.). Also connect thesub
input to the carry-in of the adder.
Verilog | |
---|---|