Behavioral Modeling: 1. Design A 4:1 MUX
Behavioral Modeling: 1. Design A 4:1 MUX
library ieee;
use ieee.std_logic_1164.all;
-------------------------------------------------
entity Mux is
port(I3: in std_logic;
I2: in std_logic;
I1: in std_logic;
I0: in std_logic;
S: in std_logic_vector(1 downto 0);
O: out std_logic
);
end Mux;
--------------------Behavioral-----------------------------
architecture behv1 of Mux is
begin
process(I3,I2,I1,I0,S)
begin
end process;
end behv1;
---------------------Data Flow---------------------------
architecture behv of Mux is
begin
end behv;
2. Design 2:4 Decoder.
entity DECODER is
port(I: in std_logic_vector(1 downto 0);
O: out std_logic_vector(3 downto 0)
);
end DECODER;
-- process statement
process (I)
begin
case I is
when "00" => O <= "0001";
when "01" => O <= "0010";
when "10" => O <= "0100";
when "11" => O <= "1000";
when others => O <= "XXXX";
end case;
end process;
end behv;
----------------------Dataflow-------------------
architecture when_else of DECODER is
begin
end when_else;
--------------------------------------------------
3. Design a 2-bit Comparator.
entity Comparator is
---------------------------------------------------
begin
process(A,B)
begin
if (A<B) then
less <= '1';
equal <= '0';
greater <= '0';
elsif (A=B) then
less <= '0';
equal <= '1';
greater <= '0';
else
less <= '0';
equal <= '0';
greater <= '1';
end if;
end process;
end behv;
---------------------------------------------------
4. Design a basic 2-bit ALU capable of adding, subtracting, anding and oring.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
---------------------------------------------------
entity ALU is
end ALU;
---------------------------------------------------
process(A,B,Sel)
begin
case Sel is
when "00" =>
Res <= A + B;
when "01" =>
Res <= A + (not B) + 1;
when "10" =>
Res <= A and B;
when "11" =>
Res <= A or B;
when others =>
Res <= "XX";
end case;
end process;
end behv;
----------------------------------------------------
5. Design a positive edge triggered JK flip flop.
library ieee;
use ieee.std_logic_1164.all;
----------------------------------------------
entity JK_FF is
port ( clock: in std_logic;
J, K: in std_logic;
reset: in std_logic;
Q, Qbar: out std_logic
);
end JK_FF;
-----------------------------------------------
begin
p: process(clock, reset) is
begin
if (reset='1') then
state <= '0';
case (input) is
when "11" =>
state <= not state;
when "10" =>
state <= '1';
when "01" =>
state <= '0';
when others =>
null;
end case;
end if;
end process;
-- concurrent statements
Q <= state;
Qbar <= not state;
end behv;