3-3
答:1.IF-ELSIF
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY MUX41A IS
PORT (A,B,C,D,S0,S1,S2,S3:IN STD_LOGIC;
Y:OUT STD_LOGIC);
END ENTITY MUX41A;
ARCHITECTURE BHV OF MUX41A IS
BEGIN
PROCESS(S0,S1,S2,S3,A,B,C,D)
BEGIN
IF S0=’0’ THEN Y<=A;
ELSIF S1=’0’ THEN Y<=B;
ELSIF S2=’0’ THEN Y<=C;
ELSIF S2=’0’ THEN Y<=D;
ELSE NULL;
END IF;
END PROCESS;
END BHV;
2.CASE语句
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY MUX41A IS
PORT (A,B,C,D,S0,S1,S2,S3:IN STD_LOGIC;
Y:OUT STD_LOGIC);
END ENTITY MUX41A;
ARCHITECTURE BHV OF MUX41A IS
SIGNAL S :STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
S<=S3&S2&S1&S0;
PROCESS(S0,S1,S2,S3,A,B,C,D) BEGIN
CASE (S) IS
WHEN “0111” => Y<=D;
WHEN “1011” => Y<=C;
WHEN “1101” => Y<=B;
WHEN “1110” => Y<=A;
WHEN OTHER=> NULL;
END CASE;
END PROCESS;
END BHV;
3.WHEN-ELSE
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY MUX41A IS
PORT (A,B,C,D,S0,S1,S2,S3:IN STD_LOGIC;
Y:OUT STD_LOGIC);
END ENTITY MUX41A;
ARCHITECTURE BHV OF MUX41A IS
SIGNAL S :STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
S<=S3&S2&S1&S0;
Y<=A WHEN S=“1110” ELSE
Y<=B WHEN S=“1101” ELSE
Y<=C WHEN S=“1011” ELSE
Y<=D WHEN S=“0111” ELSE
NULL;
END BHV;
3-4解:1.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY H_SUBER IS
PORT ( x, y : IN STD_LOGIC;
diff, s_out : OUT STD_LOGIC);
END ENTITY H_SUBER;
ARCHITECTURE fh1 OF H_SUBER IS
BEGIN
s_out <= (NOT x ) AND y;
diff <= x XOR y;
END ARCHITECTURE fh1;
(2)全减器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY F_SUBER IS
PORT ( X,Y,sub_in : IN STD_LOGIC;
diff,s_out : OUT STD_LOGIC);
END ENTITY F_SUBER;
ARCHITECTURE fd1 OF F_SUBER IS
COMPONENT H_SUBER
PORT (x ,y : IN STD_LOGIC; s_out ,diff : OUT STD_LOGIC);
END COMPONENT;
SIGNAL net1, net2, net3: STD_LOGIC;
BEGIN
u1 : H_SUBER PORT MAP(x=>X, y=>Y, diff=>net1, s_out=>net2);
u2 : H_SUBER PORT MAP(x=>net1, y=>sub_in, diff=>diffr, s_out=>net3);
sub_out <= net2 OR net3;
END fd1;