5 - Simplifying our generic adder
ObjectiveThis example will focus on:
- VHDL variables
- IEEE integer type
- IEEE type conversions
ImplementationSo far we have expanded our basic logic gate design of a simple one-bit adder into a generic N-bit full adder, always reusing the basic design. Now that we understand basics of instantiation and entities, let's rewrite our generic adder with add operations, instead of gates, thus not reusing any of previously written adders.
Note the addition of a default value on the generic definition. If not supplied by instantiation, then this value will be used for the generic.
This is also the first time we used variables inside a process. Variable assignment differ from signal assignment because their value is "set" immediatly, instead of being "set" only when process evaluation ends. Also the assignment operator for variables is different, as you can see.
Hopefully your synthesis tool will identify this design as an adder with carry in and carry out.
Here's a snippet from synthesis (more on synthesis later) of this design with Xilinx XST:
So it seems synthesis tool found out what we wanted. This is very good, but unfortunately not always the case.
What synthesis tool did here was to infer an adder from the design, instead of us instantiating it directly.