entity rom is port( addr: in std_logic_vector(0 to 3); ce: in std_logic; data:out std_logic_vector(7 downto 0); ) end rom;
以上port语句有无错误? 有 ,有的话请在原程序相应位置改正。(4)
architecture behave of rom is begin
process(ce,addr) begin if ce='0' then case addr is when \ data<=\ when \ data<=\ when \ data<=\ when \ data<=\ when \ data<=\ when \ data<=\ when \ data<=\ when \ data<=\ else data:=\ --data <= “00000000”; end if; end process; end behave;
21
(6) when \ data<=\ when \ data<=\ when \ data<=\ when \ data<=\ when \ data<=\ when \ data<=\ when \ data<=\ when others=> data<=\end case; (8) (10)
以上architecture中有哪些错误?请在原程序相应位置改正。 得分 四、 编程(共50分,除特殊声明,实体可只写出PORT语句,结构体要写完整)
1、用IF语句编写一个二选一电路,要求输入a、b, sel为选择端,输出q。(本题10分)
Entity sel2 is Port (
a,b : in std_logic; sel : in std_logic; q : out std_logic ); End sel2;
Architecture a of sel2 is begin
if sel = ‘0’ then
q <= a;
(6)
(3)
else
q <= b;
(9)
end if;
(10)
end a;
2、编写一个4位加法计数器VHDL程序的进程(不必写整个结构框架),要求复位信号reset低电平时计数器清零,变高后,在上升沿开始工作;输入时钟信号为clk,输出为q。(本题10分)
Process(reset,clk) begin
(2)
if reset = ‘0’ then
q <= “0000”;
(4) (6)
elsif clk’event and clk = ‘1’ then
22
q <= q + 1; (9)
end if;
(10)
end process;
3、填写完成一个8-3线编码器的真值表(5分),并写出其VHDL程序(10分)。
8 -3线编码器真值表
en 1 1 1 1 1 1 1 1 0 b 00000000 00000010 00000100 00001000 00010000 00100000 01000000 10000000 xxxxxxxx y0y1y2 000 001 010 011 100 101 110 111 高阻态
entity eight_tri is port( b: in std_logic_vector(7 downto 0); en: in std_logic; y: out std_logic_vector(2 downto 0) ); end eight_tri;
architecture a of eight_tri is
signal sel: std_logic_vector(8 downto 0); begin sel<=en & b; y<= “000” when (sel=”100000001”)else “001” when (sel=”100000010”)else “010” when (sel=”100000100”)else “011” when (sel=”100001000”)else “100” when (sel=”100010000”)else “101” when (sel=”100100000”)else “110” when (sel=”101000000”)else
23
(3)
(4)
end a;
“111” when (sel=”110000000”)else “zzz”;
(9) (10)
4、根据已给出的全加器的VHDL程序,试写出一个4位逐位进位全加器的VHDL程序。(本题15分)
library IEEE;
use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all;
entity adder is port ( a,b,c: in std_logic; carr: inout std_logic; sum: out std_logic ); end adder;
architecture adder_arch of adder is begin sum <= a xor b xor c; carr <= (a and b) or (b and c) or (a and c);
end adder_arch;
entity full_add is port ( a,b: in std_logic_vector (3 downto 0); carr: inout std_logic_vector (4 downto 0); sum: out std_logic_vector (3 downto 0) ); end full_add; (5)
architecture full_add_arch of full_add is component adder port ( a,b,c: in std_logic; carr: inout std_logic;
24
sum: out std_logic );
end component;
begin carr(0)<='0'; u0:adder port map(a(0),b(0),carr(0),carr(1),sum(0)); u1:adder port map(a(1),b(1),carr(1),carr(2),sum(1)); u2:adder port map(a(2),b(2),carr(2),carr(3),sum(2)); u3:adder port map(a(3),b(3),carr(3),carr(4),sum(3)); end full_add_arch; 得分
(10)
(15)
五、附加题(10分,本题可产生附加分,全卷不能超过100分)
完成下面moore状态机程序,该设计为一个存储控制器状态机。能够根据微处理器的读写周期,分别对存储器输出写使能WE和读使能OE信号。
工作过程:存储控制器的输入信号为微处理器的就绪READY及读写read_write信号。当上电复位后,或read有效时,存储控制器开始工作,并在下一个时钟周期判断本次作业任务是读存储器还是写存储器。判断的依据是,当read_write有效时为读操作,否则为写操作。也就是说非读即写。读操作时,OE信号有效,写操作时,WE信号有效。当READY信号有效时,表示读本次作业处理完成,并使控制器恢复到初始状态。
控制器真值表和状态图如下。
存储控制器真值表 状态 OE 空闲(IDLE) 判断(DECISION) 写(WRITE) 读(READ)
0 0 0 1 输出 WE 0 0 1 0 25