8.parallel Addrer GenerateRONAK
8.parallel Addrer GenerateRONAK
Practical No. 08
Aim: Design 4 bit parallel adder using generate statement and verify the design using test
bench. (Use Generic and Generate statement)
AIM: Design 4 bit parallel adder using generate statement and verify the design using test
bench. (Use Generic and Generate statement)
OBJECTIVE:
THEORY:-
A single full adder performs the addition of two one bit numbers and an input carry. But
a Parallel Adder is a digital circuit capable of finding the arithmetic sum of two binary
numbers that is greater than one bit in length by operating on corresponding pairs of bits in
parallel. It consists of full adders connected in a chain where the output carry from each full
adder is connected to the carry input of the next higher order full adder in the chain. A n bit
parallel adder requires n full adders to perform the operation. So for the two-bit number,
two adders are needed while for four bit number, four adders are needed and so on. Parallel
adders normally incorporate carry look-ahead logic to ensure that carry propagation between
subsequent stages of addition does not limit addition speed.
Here's a step-by-step guide to design a 4-bit parallel adder using generate statements
in Verilog:
1.Define Inputs and Outputs: Declare the input signals A and B (both 4 bits wide), the
carry-in (Cin), and the output signals Sum (4 bits wide) and the carry-out (Cout).
2. Generate the Full Adders: Use a generate statement to create four full adders, each
adding one bit of A, B, and the carry-in, and generating one bit of the sum and the
carry-out. Each full adder will have inputs A[i], B[i], Cin, and outputs Sum[i] and
Cout[i], where i ranges from 0 to 3.
3. Connect the Full Adders: Wire up the inputs and outputs of the full adders such that
each adder takes the corresponding bits of A, B, and carry-in, and produces the
respective sum and carry-out.
4. Top-Level Module: Define a top-level module that instantiates the 4-bit parallel
adder and connects it to the input and output ports.
A 1-bit full adder takes three inputs: two operands (a and b) and a carry-in (cin), and
produces two outputs: the sum and a carry-out (cout). The logic equations are:
Multiple full adders can be chained together to build an N-bit adder, where the carry-
out from one stage becomes the carry-in to the next.
The generate statement allows repeating a block of code with varying parameters. In the
context of a parallel adder:
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity parallel_adder is
generic (
N : integer := 4 -- Width of the adder
);
Port (
a : in STD_LOGIC_VECTOR(N-1 downto 0);
b : in STD_LOGIC_VECTOR(N-1 downto 0);
cin : in STD_LOGIC;
sum : out STD_LOGIC_VECTOR(N-1 downto 0);
cout : out STD_LOGIC
);
end parallel_adder;
TESTBENCH:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity tb_parallel_adder is
end tb_parallel_adder;
-- Component Declaration
component parallel_adder
generic (
N : integer := 4
);
Port (
a : in STD_LOGIC_VECTOR(N-1 downto 0);
b : in STD_LOGIC_VECTOR(N-1 downto 0);
cin : in STD_LOGIC;
sum : out STD_LOGIC_VECTOR(N-1 downto 0);
cout : out STD_LOGIC
);
end component;
begin
uut: parallel_adder
generic map (N => N)
port map (
a => a,
b => b,
cin => cin,
sum => sum,
cout => cout
);
process
begin
-- Test Case 1
a <= "0001";
b <= "0010";
cin <= '0';
wait for 10 ns;
-- Test Case 2
a <= "1111";
b <= "0001";
cin <= '0';
wait for 10 ns;
-- Test Case 3
a <= "1010";
b <= "0101";
cin <= '1';
wait for 10 ns;
-- Test Case 4
a <= "1001";
b <= "1001";
cin <= '1';
wait for 10 ns;
wait;
end process;
end Behavioral;
WAVEFORM:
RESULT:-
CONCLUSION:
REFERENCE:
• VHDL Primer–J Bhasker –Pearson Education