当前位置:文档之家› ALU(算术逻辑运算单元)的设计,南京理工大学紫金学院vhdl实验报告,eda

ALU(算术逻辑运算单元)的设计,南京理工大学紫金学院vhdl实验报告,eda

EDA技术与应用实验报告实验名称:ALU(算术逻辑运算单元)的设计姓名:学号:班级:通信时间:2013南京理工大学紫金学院电光系一、实验目的1、学习包集和元件例化语句的使用。

2、学习ALU电路的设计。

二、实验原理1、ALU原理ALU的电路原理图如图1 所示,主要由算术运算单元、逻辑单元、选择单元构成。

图1ALU功能表如表1 所示。

表12、元件、包集在结构体的层次化设计中,采用结构描述方法就是通过调用库中的元件或者已经设计好的模块来完成相应的设计。

在这种结构体中,功能描述就像网表一样来表示模块和模块之间的互联。

如ALU 是由算术单元、逻辑单元、多路复用器互相连接而构成。

而以上三个模块是由相应的VHDL 代码产生的,在VHDL 输入方式下,如果要将三个模块连接起来,就要用到元件例化语句。

元件例化语句分为元件声明和元件例化。

(1)元件声明在VHDL 代码中要引入设计好的模块,首先要在结构体的说明部分对要引入的模块进行说明。

然后使用元件例化语句引入模块。

元件声明语句格式:component 引入的元件(或模块)名port(端口说明);end component;注意:元件说明语句要放在“architecture”和“begin”之间。

(2)元件例化语句为将引入的元件正确地嵌入到高一层的结构体描述中,就必须将被引用的元件端口信号与结构体相应端口信号正确地连接起来,元件例化语句可以实现该功能。

元件例化语句格式:标号名:元件名(模块名) port map(端口映射);标号名是元件例化语句的唯一标识,且结构体中的标识必须是唯一的;端口映射分为:位置映射、名称映射。

位置映射指 port map 中实际信号的书写顺序与component 中端口说明中的信号书写顺序一致,位置映射对书写顺序要求很严格,不能颠倒;名称映射指port map 中将引用的元件的端口信号名称赋予结构体中要使用元件的各个信号,名称映射的书写顺序要求不严格,顺序可以颠倒。

(3)包集在实体及结构体中定义的对象、数据类型,对另外代码的实体是不能使用的。

但是在同一工程的不同VHDL 文件中,有些对象、数据类型、子程序等常常被重复使用。

为方便VHDL 代码的编写,简化电路设计,故引入包集。

包集也称为程序包。

包集主要由两部分组成:程序包说明和程序包体。

其中,程序包体是可选的,一般程序包说明列出所有项的名称,而程序包体给出各项的细节。

程序包说明中包含的内容很多,只要是通用的全局量,都可以在程序包中加以说明。

主要内容如下:对象(常量、变量、信号)的数据类型说明。

对象(常量、变量、信号)子类型的数值范围说明。

函数与过程说明。

元件语句说明。

程序包说明的书写格式如下:package 程序包名 is说明语句;end 程序包名;程序包名:设计者自定义便于记忆的标识符。

说明语句:包括各种类型的说明语句。

程序包体书写格式如下:package body 程序包名 is顺序语句;end 程序包名;注意:程序包定义的内容不是自动可见的,不是自动被使用。

若某个实体及结构体设计需要使用程序包,可以使用use 语句制定要使用的程序包。

如:use work.程序包名.all;三、实验内容1、建立工程、输入代码(1)算术单元arith_unitlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity arith_unit isport (a,b:in std_logic_vector(7 downto 0);sel:in std_logic_vector(2 downto 0);cin:in std_logic;x:out std_logic_vector(7 downto 0));end arith_unit;architecture arith_unit of arith_unit isbeginwith sel selectx <=a when "000",a+1 when "001",a-1 when "010",b when "011",b+1 when "100",b-1 when "101",a+b when "110",a+b+cin when "111",null when others;end arith_unit;(2)逻辑单元logic_unitlibrary ieee;use ieee.std_logic_1164.all;entity logic_unit isport (a,b:in std_logic_vector(7 downto 0);sel:in std_logic_vector(2 downto 0);end logic_unit;architecture logic_unit of logic_unit isbeginwith sel selectx <=not a when "000",not b when "001",a andb when "010",a orb when "011",a nandb when "100",a norb when "101",a xorb when "110",a xorb when "111",null when others;end logic_unit;(3)多路复用器sellibrary ieee;use ieee.std_logic_1164.all;entity mux isport (arith,logic:in std_logic_vector(7 downto 0);sel:in std_logic_vector(3 downto 0);x:out std_logic_vector(7 downto 0)); end mux;architecture mux of mux isbeginwith sel(3) selectx <= arith when '0',logic when '1',null when others;end mux;(4)package定义library ieee;use ieee.std_logic_1164.all;package alu iscomponent arith_unit isport (a,b:in std_logic_vector(7 downto 0);sel:in std_logic_vector(2 downto 0);cin:in std_logic;end component;component logic_unit isport (a,b:in std_logic_vector(7 downto 0);sel:in std_logic_vector(2 downto 0);x:out std_logic_vector(7 downto 0)); end component;component mux isport (arith,logic:in std_logic_vector(7 downto 0);sel:in std_logic_vector(3 downto 0);x:out std_logic_vector(7 downto 0)); end component;end alu;(5)alu_unit单元library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use work.alu.all;entity alu_unit isport (a,b:in std_logic_vector(7 downto 0);cin:in std_logic;clk:in std_logic;sel:buffer std_logic_vector(3 downto 0);y:out std_logic_vector(7 downto 0)); end alu_unit;architecture alu_unit of alu_unit issignal x1,x2:std_logic_vector(7 downto 0);beginprocess(clk)variable s:std_logic_vector(3 downto 0);beginif(clk'event and clk='1') thens:=s+1;end if;sel<=s;end process;U1:arith_unit port map(a,b,sel(2 downto 0),cin,x1);U2:logic_unit port map(a,b,sel(2 downto 0),x2);U3:mux port map(x1,x2,sel,y);end alu_unit;2、编译3、仿真4、管脚配置5、下载将文件下载到实验箱,对实验箱进行操作。

四、小结与体会通过本次实验,我们学会了包集和元件例化语句的使用,学会了ALU电路的设计。

相关主题