Behavioralmodelprograms
Behavioralmodelprograms
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity MUX_4X1 is
port(
A : in STD_LOGIC;
B : in STD_LOGIC;
C : in STD_LOGIC;
D : in STD_LOGIC;
S : in STD_LOGIC_VECTOR(1 down to 0);
Y : out STD_LOGIC
);
end MUX_4X1;
architecture MUX_BEH of MUX_4X1 is
begin
PROCESS(A,B,C,D,S)
BEGIN
CASE S IS
WHEN "00" => Y<= A;
WHEN "01" => Y<= B;
WHEN "10" => Y<= C;
WHEN "11" => Y<= D;
WHEN OTHERS => NULL;
END CASE;
END PROCESS;
end MUX_BEH;
--1-bit comparator using behavioral style.
entity comp is
port ( a: in bit_vector(0 to 1);e: out bit_vector(2 downto 0));
end entity;
1
when "01" => e <="010";
when "10" => e <="001";
when "11" => e <="100";
when others => null;
end case;
end process;
end architecture;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity \4_comp\ is
port(
a : in STD_LOGIC_VECTOR(0 to 3);
b : in STD_LOGIC_VECTOR(0 to 3);
agtb : out STD_LOGIC;
altb : out STD_LOGIC;
aeqb : out STD_LOGIC
);
end \4_comp\;
architecture \4_comp_beh\ of \4_comp\ is
begin
process(a,b)
begin
if(a>b) then
agtb<= '1';
aeqb<='0';
altb<= '0';
elsif(a<b) then
agtb<= '0';
aeqb<='0';
altb<= '1';
elsif(a=b)then
agtb<= '0';
aeqb<='1';
altb<= '0';
end if;
2
end process;
end \4_comp_beh\;
--vhdl code for halfadder using Behavioral style model.
entity ha is
port( a, b: in bit; sum,carry: out bit);
end entity;
architecture ha1 of ha is
begin
process (a,b)
begin
if (a ='0' and b='0') then
sum <= '0';
carry<='0';
elsif( a='0' and b='1')then
sum<= '1';
carry<='0';
elsif( a='1' and b='0')then
sum<= '1';
carry<='0';
elsif( a='1' and b='1')then
sum<= '0';
carry<='1';
end if;
end process;
end architecture;
3
elsif( a='1' and b='0')then
sum<= '1';
borrow<='0';
elsif( a='1' and b='1')then
sum<= '0';
borrow<='0';
end if;
end process;
end architecture;
4
sum <= '1';
carry <='1';
end if;
end process;
end architecture;
--vhdl code for B2G code converter using behavioral model.
entity b2g is
port(
b : in STD_LOGIC_VECTOR(3 downto 0);
g : out STD_LOGIC_VECTOR(3 downto 0)
);
end b2g;
5
--vhdl code for G2B code converter using behavioral model.
entity g2b is
port(
g : in STD_LOGIC_VECTOR(3 downto 0);
b : out STD_LOGIC_VECTOR(3 downto 0)
);
end g2b;
--vhdl code for Bcd2 7-segment code converter using behavioral model.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
6
entity bcd_seven is
port(
bcd : in STD_LOGIC_VECTOR(3 downto 0);
segment : out STD_LOGIC_VECTOR(6 downto 0)
);
end bcd_seven;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity bcd_excess is
port(
b : in STD_LOGIC_VECTOR(3 downto 0);
excess3 : out STD_LOGIC_VECTOR(3 downto 0)
);
end bcd_excess;
7
begin
process (b)
begin
case b is
when "0000"=>excess3<="0011";
when "0001"=>excess3<="0100";
when "0010"=>excess3<="0101";
when "0011"=>excess3<="011";
when "0100"=>excess3<="0111";
when "0101"=>excess3<="1000";
when "0110"=>excess3<="1001";
when "0111"=>excess3<="1010";
when "1000"=>excess3<="1011";
when "1001"=>excess3<="1100";
when "1010"=>excess3<="1110";
when others => null;
end case;
end process;
end bcd_excess_beh;
8
z(3)<= s0bar and s1bar;
z(2)<=s0bar and s1;
z(1)<= s0 and s1bar;
z(0)<= s0 and s1;
else
z<="0000";
end if;
end process;
end decoder_beh;
--VHDL Code for encoder 8X3 using behavioral model.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity encoder is
port(
d : in STD_LOGIC_VECTOR(0 to 7);
a : out STD_LOGIC_vector(0 to 2 )
);
end encoder;
begin
process (d)
begin
case d is
when "10000000"=> a<= "000";
when "01000000"=> a<="001";
when "00100000"=> a<="010";
when "00010000"=> a<="011";
when "00001000"=> a<="100";
when "00000100"=> a<="101";
when "00000010"=> a<="110";
when "00000001"=> a<="111";
when others => null;
end case;
end process;
9
end encoder_beh;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity parity is
port(
d : in STD_LOGIC_VECTOR(3 downto 0);
par_even : out STD_LOGIC;
par_odd : out STD_LOGIC);
end parity;
architecture parity of parity is
begin
p1:process(d)
begin
case d is
when "0000"=> par_even<='0';par_odd<='1';
when "0001"=> par_even<='1'; par_odd<='0';
when "0010"=> par_even<='1'; par_odd<='0';
when "0011"=> par_even<='0'; par_odd<='1';
when "0100"=> par_even<='1'; par_odd<='0';
when "0101"=> par_even<='0'; par_odd<='1';
when "0110"=> par_even<='0'; par_odd<='1';
when "0111"=> par_even<='1'; par_odd<='0';
when "1000"=> par_even<='1'; par_odd<='0';
when "1001"=> par_even<='0'; par_odd<='1';
when "1010"=> par_even<='0'; par_odd<='1';
when "1011"=> par_even<='1'; par_odd<='0';
when "1100"=> par_even<='0'; par_odd<='1';
when "1101"=> par_even<='1'; par_odd<='0';
when "1110"=> par_even<='1'; par_odd<='0';
when "1111"=> par_even<='0'; par_odd<='1';
when others=> null;
end case;
end process;
end parity;
10