3-3 试分别用IF_THEN语句、WHEN_ELSE和CASE语句的表达方式写出4选1多路选择器的VHDL程序,选择控制端有4个输入:SO、S1、S2、S3。当且仅当S0=0时:Y=A;S1=0:Y=B:S2=0时,Y=C;S3=0时:Y=D。
解:LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY mux41 IS
PORT (a,b,c,d: IN STD_LOGIC;
s0: IN STD_LOGIC;
s1: IN STD_LOGIC;
y: OUT STD_LOGIC);
END ENTITY mux41;
ARCHITECTURE case_mux41 OF mux41 IS
SIGNAL s0s1 : STD_LOGIC_VECTOR(1 DOWNTO 0);
BEGIN
s0s1<=s1&s0;
PROCESS(s0s1,a,b,c,d)
BEGIN
CASE s0s1 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 ARCHITECTURE case_mux41;
3-4
解:IBRARY IEEE; --1位二进制全减器顺层设计描述
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY f_suber IS
PORT(xin,yin,sub_in: IN STD_LOGIC;
sub_out,diff_out: OUT STD_LOGIC);
END ENTITY f_suber;
ARCHITECTURE fs1 OF f_suber IS
COMPONENT h_suber --调用半减器声明语句
PORT(x, y: IN STD_LOGIC;
diff,s_out: OUT STD_LOGIC);
END COMPONENT;
SIGNAL a,b,c: STD_LOGIC; --定义1个信号作为内部的连接线。
BEGIN
u1: h_suber PORT MAP(x=>xin,y=>yin, diff=>a, s_out=>b);
u2: h_suber PORT MAP(x=>a, y=>sub_in, diff=>diff_out,s_out=>c);
sub_out <= c OR b;
END ARCHITECTURE fs1;
(2):
LIBRARY IEEE; --1位二进制全减器顺层设计描述
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY f_suber IS
PORT(xin,yin,sub_in: IN STD_LOGIC;
sub_out,diff_out: OUT STD_LOGIC);
END ENTITY f_suber;
ARCHITECTURE fs1 OF f_suber IS
COMPONENT h_suber --调用半减器声明语句
PORT(x, y: IN STD_LOGIC;
diff,s_out: OUT STD_LOGIC);
END COMPONENT;
SIGNAL a,b,c: STD_LOGIC; --定义1个信号作为内部的连接线。
BEGIN
u1: h_suber PORT MAP(x=>xin,y=>yin, diff=>a, s_out=>b);
u2: h_suber PORT MAP(x=>a, y=>sub_in, diff=>diff_out,s_out=>c);
sub_out <= c OR b;
END ARCHITECTURE fs1;