use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all;
entity shifter is
port(data :in std_logic_vector(7 downto 0); clk:in std_logic;
shiftleft,shiftright:in std_logic; reset:in std_logic;
mode:in std_logic_vector(1 downto 0);
qout:buffer std_logic_vector(7 downto 0)); end shifter;
architecture art of shifter is begin
process begin
process (rising_edge(clk)); --等待上升沿 if reset='1' then qout<=\同步复位 else
case mode is
when \“0” ; --右移一位 when \“0” ; --左移一位
when \qout ; --不移,并行输入 when others=>null; end case ; end if;
end process; end art;
(十三) 在下面横线上填上合适的语句,完成计数器的设计。
说明:设计一个带有异步复位和时钟使能的一位八进制加法计数器(带进位输出端)。 library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity cnt8 is
port (clk,rst,en : in std_logic;
cq : out std_logic_vector( 2 downto 0); cout : out std_logic ); end cnt8;
architecture behav of cnt8 is begin
process(clk, rst, en)
signal cqi : std_logic_vector(2 downto 0); begin
if rst = '1' then cqi := “000”;
if clk'event and clk='1' then if en = '1' then
if cqi < \“0” ; else cqi := cqi+1 ; end if;
end if; end if;
if cqi = \ else cout <= '0';
end if;
cq <= cqi; end process; end behav;
(十四) 在下面横线上填上合适的语句,完成序列信号发生器的设计。
说明:已知发送信号为”10011010”,要求以由高到低的序列形式一位一位的发送,发送开始前及发送完为低电平。 library ieee;
use ieee.std_logic_1164.all; entity xulie is
port (res, clk: in std_logic; y: out std_logic ); end;
architecture arch of xulie is
signal reg:std_logic_vector(7 downto 0); begin
process(clk, res) begin
if(clk’event and clk=’1’) then if res=’1’ then
y<=’0’; reg<= “10011010” ; --同步复位,并加载输入 else y<= reg(7) ; --高位输出
reg<= reg(6 downto 0)&”0” ; --左移,低位补0 end if; end if;
end process; end;
(十五) 在下面横线上填上合适的语句,完成数据选择器的设计。
说明:采用元件例化的设计方法,先设计一个2选1多路选择器,再使用3个2选1多路选择器构成一个4选1多路选择器。
library ieee; --2选1多路选择器的描述 use ieee.std_logic_1164.all; entity mux21 is
port(a,b,sel : in std_logic; y : out std_logic); end mux21;
architecture art of mux21 is begin
y<=a when sel='0' else b; end ;
library ieee; --4选1多路选择器的描述 use ieee.std_logic_1164.all; entity mux41 is
port(a,b,c,d : in std_logic; s1,s2 : in std_logic;
y:out std_logic) ; end;
architecture art of mux41 is component mux41
port(a,b,sel : in std_logic; y : out std_logic); end component;
signal y1,y2:std_logic; begin
u1: mux21 port map(a,b,s1, S2 );
u2: mux21 port map(c,d, ,y2); u2: mux21 port map(y1,y2, ,y); end ;
(十六) 在下面横线上填上合适的语句,完成8位奇偶校验电路的设计。 library ieee;
use ieee.std_logic_1164.all; entity pc is
port ( a : in std_logic_vector(7 downto 0); y : out std_logic ); end pc;
architecture a of pc is begin process(a).
variable tmp: std_logic; begin
tmp := '0';
for i in 0 to 7 loop
tmp:= a(0)xor a(1)xor a(2)xor a(3)xor a(4)xor a(5)xor a(6) ; end loop; y<= tmp ; end process;
end;
(十七)在下面横线上填上合适的语句,完成一个逻辑电路的设计, 其布尔方程为y=(a+b)(c⊙d)+(b⊕f).
LIBRARY ieee; USE ieee.std_logic_1164.ALL; ENTITY comb IS
PORT(a, b,c,d,e,f,: IN std_logic; y: OUT std_logic); END comb;
ARCHITECTURE one OF comb IS BEGIN
y<=(a OR b) AND (c 异或 d) OR (b xor f); END ARCHITECTURE one;
(十八)在下面横线上填上合适的语句,完成一个带使能功能的二-十进制译码器的设计。 LIBRARY ieee;
USE ieee.std_logic_1164.ALL; ENTITY my2to10 IS
PORT (en: IN std_logic;
din: IN std_logic_vector( 3 DOWNTO 0); pout: OUT std_logic_vector(9 DOWNTO 0) ); END;
ARCHITECTURE arch OF my2to10 IS BEGIN
PROCESS(en, din) BEGIN
IF en=’1’ THEN CASE din IS
WHEN \WHEN \WHEN \WHEN \WHEN \WHEN \WHEN \WHEN \WHEN \WHEN \WHEN OTHERS => pout<=\END CASE; END IF;
END PROCESS;

