03 Package
03 Package
ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Mux is
port( I3: in std_logic_vector(2 downto 0);
I2: in std_logic_vector(2 downto 0);
I1: in std_logic_vector(2 downto 0);
I0: in std_logic_vector(2 downto 0);
S: in std_logic_vector(1 downto 0);
O: out std_logic_vector(2 downto 0)
);
end Mux;
architecture behv1 of Mux is
begin
process(I3,I2,I1,I0,S)
architecture behv2 of Mux is
begin
begin
-- use case statement
-- use when.. else statement
case S is
O <= I0 when S="00" else
when "00" => O <= I0;
I1 when S="01" else
when "01" => O <= I1;
I2 when S="10" else
when "10" => O <= I2;
I3 when S="11" else
when "11" => O <= I3;
"ZZZ";
when others => O <= "ZZZ";
end case;
end behv2;
end process;
end behv1;
entity DECODER is
port( I: in std_logic_vector(1 downto 0);
O: out std_logic_vector(3 downto 0)
);
end DECODER;
end behv;
A I1
B I2
Multiplexeur S S
C
D e1 e2 e3 e4
1
A
DEMUX
B
F
C
D
S1 S0
entity ADDER is
Adder
generic(n: natural :=2);
port( A: in std_logic_vector(n-1 downto 0);
B: in std_logic_vector(n-1 downto 0);
carry: out std_logic;
sum: out std_logic_vector(n-1 downto 0)
);
end ADDER;
architecture behv of ADDER is
begin
end behv;
multiplier
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity multiplier is
port( num1, num2: in std_logic_vector(1 downto 0);
product: out std_logic_vector(3 downto 0)
);
end multiplier;
architecture behv of multiplier is
begin
process(num1, num2)
variable num1_reg: std_logic_vector(2 downto 0);
variable product_reg: std_logic_vector(5 downto 0);
begin
num1_reg := '0' & num1;
product_reg := "0000" & num2;
for i in 1 to 3 loop
if product_reg(0)='1' then
product_reg(5 downto 3) := product_reg(5 downto 3)
+ num1_reg(2 downto 0);
end if;
product_reg(5 downto 0) := '0' & product_reg(5 downto 1);
end loop;
end behv;
register
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity reg is
begin
end process;
-- concurrent statement
Q <= Q_tmp;
end behv;