library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mpadd is
port ( a : in std_logic_vector(31 downto 0);
b : in std_logic_vector(31 downto 0);
y : out std_logic_vector(31 downto 0)
);
end mpadd;
architecture mpadd of mpadd is
return std_logic_vector is
Function to_integer(x:in std_logic_vector(6 downto 0))
return integer is
variable sum :integer:=0;
variable Temp :Std_logic_vector(6 downto 0);
begin
temp:=x;
xxx: for i in 0 to 6 loop
if (temp(i)='1')then
sum:=sum+2**i;
else
Sum:=Sum;
end if;
end loop;
return sum;
end function;
variable MaIn : std_logic_vector(22 downto 0); -- Internal Register
variable MbIn : std_logic_vector(22 downto 0); -- Internal Register
variable Ea,Eb : std_logic_vector(7 downto 0); -- Two Exponents including Sign
variable IR : std_logic_vector(22 downto 0); -- Resultant Mantissa
variable IE : std_logic_vector(6 downto 0); -- Resultant Exponent
variable Ns : integer; -- Number Of Shifts
variable Ma,Mb : std_logic_vector(22 downto 0); -- Mangitude Of Two mantissas
variable ES : std_logic; -- Sign Of Resulant Exponent
variable a,b : std_logic; -- Sign Of Two exponents
variable s1,s2 : std_logic; -- Sign Of Two mantissas
variable Sign : std_logic; -- Sign Of Resultant Mantissa
variable W,Z : std_logic_vector(1 downto 0);
variable X : std_logic_vector(31 downto 0); -- Final Result
begin
MaIn:=AccOut(22 downto 0);
MbIn:=Data(22 downto 0);
Ea :=AccOut(30 downto 23);
Eb :=Data(30 downto 23);
a :=AccOut(30);
b :=Data(30);
Z :=(a&b);
case Z is
when "00" => Mb:=MbIn;
Ma:=MaIn;
if((Ea(6 downto 0))<(Eb(6 downto 0))) then
NS:=to_integer(Eb(6 downto 0)-Ea(6 downto 0));
for x in 1 to NS loop
Ma := ('0' & Ma(22 downto 1));
end loop;
IE:=Eb(6 downto 0);
Es:=Eb(7)
elsif((Eb(6 downto 0))<(Ea(6 downto 0))) then
NS:=to_integer(Ea(6 downto 0)-Eb(6 downto 0));
for x in 1 to NS loop
Mb:=('0' & Mb(22 downto 1));
end loop;
IE:=Ea(6 downto 0);
Es:=Ea(7);
else
NS:=Ns;
Ma:=Ma;
Mb:=Mb;
IE:=IE;
ES:=Ea(7);
end if;
when "01" => Mb:=MbIn;
Ma:=MaIn;
NS:=to_integer(Ea(6 downto 0)+Eb(6 downto 0));
for x in 1 to NS loop
Mb:=('0' & Mb(22 downto 1));
end loop;
IE:=Ea(6 downto 0);
ES:=Ea(7);
when "10" => Mb:=MbIn;
Ma:=MaIn;
NS:=to_integer(Eb(6 downto 0)+Ea(6 downto 0));
for x in 1 to NS loop
Ma:=('0' & Ma(22 downto 1));
end loop;
IE:=Eb(6 downto 0);
ES:=Eb(7);
when "11" => Mb:=MbIn;
Ma:=MaIn;
if((Ea(6 downto 0))<(Eb(6 downto 0))) then
NS:=to_integer(Eb(6 downto 0)-Ea(6 downto 0));
for x in 1 to NS loop
Mb:=('0' & Mb(22 downto 1));
end loop;
IE:=Ea(6 downto 0);
ES:=Ea(7);
elsif((Eb(6 downto 0))<(Ea(6 downto 0))) then
NS:=to_integer(Ea(6 downto 0)-Eb(6 downto 0));
for x in 1 to NS loop
Ma:=('0' & Ma(22 downto 1));
end loop;
IE:=Eb(6 downto 0);
ES:=Eb(7);
else
NS:=Ns;
Ma:=Ma;
Mb:=Mb;
IE:=IE;
ES:=Ea(7);
end if;
when others => Null;
end case;
IR:=Ma+Mb;
s1:=Accout(31);
s2:=Data(31);
W :=(s1&s2);
case W is
when "00" => sign:='0';
when "11" => sign:='1';
when "01" => if(Ea>Eb) then
sign:='0';
elsif(Ea sign:='1'; elsif(Ea=Eb) then if(Ma>Mb) then sign:='0'; elsif(Ma sign:='1'; elsif(Ma=Mb) then sign:='0'; else sign:=sign; end if; else sign:=sign; end if; when "10" => if(Ea>Eb) then sign:='1'; elsif(Ea sign:='0'; elsif(Ea=Eb) then if(Ma>Mb) then sign:='1'; elsif(Ma sign:='0'; elsif(Ma=Mb) then sign:='0'; else sign:=sign; end if; else sign:=sign; end if; when others => null; end case; --***********Final Result After Addition*************************** X:=(sign & ES & IE & IR(22 downto 0)); return X; end function; begin process(a,b) begin y<=float_add(a,b); end process; end mpadd;
vhdl code for ascending order of numbers
A parallel adder is a binary adder that can possibly form sum and carry the outputs for addend and augend words that operate on corresponding pairs addend and augend bits in parallel.
karthika only know answer to this question
It is a digital circuit that produces the arithmetic sum of two binary number .It can be constructed with the full adders connected in cascade,with the output carry from each full adder connected to the input carry of the next full adder in the chain.
150 grams
In structural modeling of VHDL, the concept of components is used. In this model, the system to be designed is considered as a combination of sub structures. These sub structures are called components.For example, a full adder is a combination of two half adders and an or gate. Hence, the components used for designing a full adder arehalf adderOR gateInitially, these components are mentioned in the architecture of a full adder VHDL program. We call this as component initiation. Then the components are called onto the main program and used.Remember, we are using the functionality of the components in main program but we are not coding them in the main program. The code for the component programs will be present somewhere else in the project.Means, code them once and use them infinite number of times.
A function is a subprogram written in VHDL. This program can be called and used in other programs.
After compiling a hardware description language like VHDL, it is required to apply inputs to the program in order to obtain out puts. Applying the inputs involves initial conditions. As the systems designed using VHDL are electronic, the initial conditions plays a vital role. Hence, all these conditions along with the information as to where the input is expected to change from 1 to 0 or 0 to 1 is provided to the VHDL program. This is done in the form of a wave or another VHDL program. These are called VHDL test benches. In other words, test benches are the means of applying inputs to VHDL program.
Half adder is a combinational circuit which can add two bits. It contains two inputs and two outputs. The same is implemented in entity declaration of VHDL program. The outputs are related to inputs as follows: SUM output is obtained by XORing the inputs and CARRY output is obtained by ANDing the inputs i. e. multiplication. The VHDL code for half adder using data flow model is given below: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity had is Port ( a : in STD_LOGIC; b : in STD_LOGIC; s : out STD_LOGIC; c : out STD_LOGIC); end had; architecture df of had is begin s<= a xor b; c<= a and b; end df;
VHDL is a hardware description language. It describes the functionality of a hardware as a program. If we know the architecture of 8085, the same can be implemented or coded using VHDL.
Since a fulladder can be obtained by using 2 halfadders & 1 OR gate.....so we have to call an halfadder program as well as an OR program......this can be implemented easily with the help of structural model rather than dataflow and behavoioural model
VHDL is a hardware description language. The purpose of any HDL is to represent hardware as a program. We can write a program (code) for any digital circuit using VHDL. With the help of this code, the output of the circuit can be observed before actually designing it physically.
There are 4 main differences between C programming and VHDL programming. C is a mid-level language, while VHDL is a hardware description language. C can handle one type of instruction, while VHDL can handle two. C does not require as much resource usage as VHDL. C can be written only with logical thinking, but a VHDL programmer must understand hardware circuits.
VHDL program follows IEEE library. This means that all the data types, commands, keywords etc. used in a VHDL program are stored in a library called IEEE library. This library will be available in the EDA tool which is executing the VHDL program. 1164 is a package where all the logic gates are defined. This is a sub part of IEEE library. As encoder program requires logic gates, we need to use 1164 package in the code.
PROGRAM:Library ieee;use ieee.std_logic_1164.all;entity ha1 isport(a,b:in bit;s,c:out bit);end ha1;architecture ha1 of ha1 isbegins
VHDL is a hardware description language. Its very purpose is to describe hardware in the form of a program. This program can be understood by the user and the system as well. By implementing the hardware as a code, it is easier to verify its functionality. Hence, to test hardware before it could actually be designed, we should use VHDL.
VHDL is basically a hardware description language. To describe hardware as a program that can be dumped into a PLD, we use VHDL. It is essential to represent hardware as program so that it can be tested before realizing it physically. If there are any errors, they can be corrected here itself.