VHDL Program of 4 bit Parallel Adder


In this article we will write a program of 4 bit parallel adder in VHDL. 4 bit parallel adder is used to add two 4 bit data. So four full adders are required to construct the 4 bit parallel adder. Now full adder is used to add 3 bit together and gives output as sum and carry.

First we define the expression of sum and carry that we will use in the program.The expression is given below:

sum= a xor b xor c
carry= a and b or b and c or c and a

Note: a,b,c are three input bits which are to added and sum and carry are the outputs of the adder.

In order to write the program first we have to declare the entity and determine total inputs and outputs we require. As we have to add two 4 bit data we declare two inputs as a and b of 4 bits. The output of program will have sum and carry so we also define sum and carry outputs as s and c of 4 bits. We will require one more input of 1 bit which will contain the carry coming from previous data so we define it as cin. Now our entity is defined let us define the architecture of the program. First we define a variable of std_logic type which will contain the value of cin. Now we use for loop in order to take one bit at a time and get the required output one by one in each bit. So the loop will run 4 times for 4 bit data. The coding of program is given below:





library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

-- Uncomment the following lines to use the declarations that are
-- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;

entity pa1 is
Port ( a : in std_logic_vector(3 downto 0);
b : in std_logic_vector(3 downto 0);
s : out std_logic_vector(3 downto 0);
c : out std_logic;
cin : in std_logic);
end pa1;

architecture pa11 of pa1 is

begin
process(a,b,cin)
variable u:std_logic;
begin
u:=cin;
for i in 0 to 3 loop
s(i)<=a(i) xor b(i) xor u;
u:=(a(i) and b(i))or(b(i) and u) or(u and a(i));
end loop;
c<=u;
end process;

end pa11;


Related Articles

Program of multiplexer in VHDL

In this article we will write a program of 4x1 multiplexer in VHDL. Multiplexers outputs are dependent on the selection lines. When selection line's value changes the output also changes. Selection line is of 2 bit, input is of 4 bit and output is of 1 bit only.

Structure of VHDL Module

This article gives the information about the structure of VHDL module. HDL stands for Hardware Description language. In HDL we have two types programs. VHDL is one of the HDL type. Read this article to know more.

More articles: VHDL program Vhdl

Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: