Professional Documents
Culture Documents
Sol 10
begin
TMP = OP xor B;
FA0:Full_Adder port map(A(0),TMP(0),OP, R(0),C1);-- R0
FA1:Full_Adder port map(A(1),TMP(1),C1, R(1),C2);-- R1
FA2:Full_Adder port map(A(2),TMP(2),C2, R(2),C3);-- R2
FA3:Full_Adder port map(A(3),TMP(3),C3, R(3),C4);-- R3
OVERFLOW = C3 XOR C4 ;
Cout = C4;
end struct;
---------------------------------------------------------------------------
Sol 11
--Code VHDL module ALU
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity ALU is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
b : in STD_LOGIC_VECTOR (2 downto 0);
c: in std_logic;
sel : in STD_LOGIC_VECTOR (1 downto 0);
result : out STD_LOGIC_VECTOR (5 downto 0));
end ALU;
component comparator_3bit
port( a : in std_logic_vector(2 downto 0);
b : in std_logic_vector(2 downto 0);
less : out std_logic;
equal : out std_logic;
greater : out std_logic);
end component;
component multiplier_3bit
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
b : in STD_LOGIC_VECTOR (2 downto 0);
p : out STD_LOGIC_VECTOR (5 downto 0));
end component;
component subtractor_3bit
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
b : in STD_LOGIC_VECTOR (2 downto 0);
bin : in STD_LOGIC;
diff : out STD_LOGIC_VECTOR (2 downto 0);
bout : out STD_LOGIC);
end component;
component adder_3bit is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
b : in STD_LOGIC_VECTOR (2 downto 0);
cin : in STD_LOGIC;
sum : out STD_LOGIC_VECTOR (2 downto 0);
cout : out STD_LOGIC);
end component;
begin
process(sel,t_comp,t_multi,t_sub,t_adder)
begin
case sel is
when "00"=>
result<=t_adder; when "01"=>
result<=t_sub; when "10"=>
result<=t_multi; when "11"=>
result<=t_comp; when others =>
result<="000000";
end case;
end process;
end Behavioral;
-------------------------
--Code VHDl adder 3 bits
library IEEE;
Solution série 2 : Logique combinatoire via VHDL
use IEEE.STD_LOGIC_1164.ALL;
entity adder_3bit is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
b : in STD_LOGIC_VECTOR (2 downto 0);
cin : in STD_LOGIC;
sum : out STD_LOGIC_VECTOR (2 downto 0);
cout : out STD_LOGIC);
end adder_3bit;
component fulladder
port( a : in STD_LOGIC;
b : in STD_LOGIC;
cin : in STD_LOGIC;
s : out STD_LOGIC;
cout : out STD_LOGIC);
end component;
signal c1,c2:std_logic;
begin
end Behavioral;
entity fulladder is
port( a : in STD_LOGIC;
b : in STD_LOGIC;
cin : in STD_LOGIC;
s : out STD_LOGIC;
cout : out STD_LOGIC);
end fulladder;
component halfadder
Port( a,b : in std_logic;
s : out STD_LOGIC;
cout : out STD_LOGIC);
end component;
signal s1,c1,c2:std_logic;
begin
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity halfadder is
Port( a,b : in std_logic;
s : out STD_LOGIC;
cout : out STD_LOGIC);
end halfadder;
begin
s <= a xor b;
cout <= a and b;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity subtractor_3bit is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
b : in STD_LOGIC_VECTOR (2 downto 0);
bin : in STD_LOGIC;
diff : out STD_LOGIC_VECTOR (2 downto 0);
bout : out STD_LOGIC);
end subtractor_3bit;
component fullsubtractor is
Port( a : in STD_LOGIC;
b : in STD_LOGIC;
bin : in STD_LOGIC;
diff : out STD_LOGIC;
bout : out STD_LOGIC);
end component;
begin
end Behavioral;
entity fullsubtractor is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
bin : in STD_LOGIC;
diff : out STD_LOGIC;
bout : out STD_LOGIC);
Solution série 2 : Logique combinatoire via VHDL
end fullsubtractor;
begin
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity multiplier_3bit is
Port( a : in STD_LOGIC_VECTOR (2 downto 0);
b : in STD_LOGIC_VECTOR (2 downto 0);
p : out STD_LOGIC_VECTOR (5 downto 0));
end multiplier_3bit;
component fulladder
Port( a : in STD_LOGIC;
b : in STD_LOGIC;
cin : in STD_LOGIC;
s : out STD_LOGIC;
cout : out STD_LOGIC);
end component;
component halfadder is
port( a,b : in std_logic;
s : out STD_LOGIC;
cout : out STD_LOGIC);
end component;
begin
end Behavioral;
Solution série 2 : Logique combinatoire via VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity comparator_3bit is
Port ( a : in std_logic_vector(2 downto 0);
b : in std_logic_vector(2 downto 0);
less : out std_logic;
equal : out std_logic;
greater : out std_logic);
end comparator_3bit;
begin
process(a,b)
begin
if (a > b ) then --condition a is greater than b
less <= '0';
equal <= '0';
greater <= '1';
elsif (a < b) then --condition a is less than b
less <= '1';
equal <= '0';
greater <= '0';
else --condition a is equals b
less <= '0';
equal <= '1';
greater <= '0';
end if;
end process;
end Behavioral;
---------------------------------------------------------------------------