博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Quartus II 实验 (二)——VHDL 4位加法器和4位乘法器
阅读量:3905 次
发布时间:2019-05-23

本文共 4082 字,大约阅读时间需要 13 分钟。

0x1 前言 

计算机组成原理实验项目要求之一,使用Quartus II的VHDL语言制作一个 4位加法器和4位乘法器,并烧到试验箱中进行测试。

关于我所使用的试验箱DICE-E213的部分介绍请参照  

 

0x2 四位乘法器

  • 首先说明目录结构:

|

|-- and4a

|-- ls283

|-- mul4p  

  • 二进制加法过程

  • 模块说明
    • and4a 乘法模块,负责将 每一位乘数 与 被乘数 相乘
    • ls283 加法模块,负责将中间结果相加。

>>> 需要特别注意的是上述每一个都是一个工程,完成以后需要进行编译;在主程序中需要将上面两个模块引入,才能正常调用。

 

  • and4a

Library ieee;                                         Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity and4a is	Port(a:in std_logic_vector(3 downto 0);	    en:in std_logic;	     r:out std_logic_vector(3 downto 0));End and4a;Architecture behave of and4a isBegin 	Process(en,a(3 downto 0))	    Begin 	         If (en='1') then	              r<=a;	         Else	              r<="0000";	         End if;	End process;End behave;
  • ls283

Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity  ls283  is		Port (o1,o2:in std_logic_vector(3 downto 0);	     res:out std_logic_vector(4 downto 0));End ls283;Architecture behave of  ls283 isBegin      Process(o1,o2)     Begin          res<=('0'&o1)+('0'&o2);     End process;End behave;
  • mul4p

这部分是主程序

Library  ieee;	Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity  mul4p  is	Port (op1,op2:in std_logic_vector(3 downto 0);	     result:out std_logic_vector(7 downto 0));End mul4p;Architecture  count  of  mul4p  is component  and4a port (a:in std_logic_vector(3 downto 0);	                en:in std_logic;	               r:out std_logic_vector(3 downto 0));End component;Component  ls283 port (o1,o2:in std_logic_vector(3 downto 0);	                 res:out std_logic_vector(4 downto 0));End component;Signal sa:std_logic_vector(3 downto 0);Signal sb:std_logic_vector(4 downto 0);Signal sc:std_logic_vector(3 downto 0);Signal sd:std_logic_vector(4 downto 0);Signal se:std_logic_vector(3 downto 0);Signal sf:std_logic_vector(3 downto 0);Signal sg:std_logic_vector(3 downto 0);--signal tmp1:std_logic;Begin     sg<=('0'&sf (3 downto 1));     --tmp1<=op1(1);     u0:and4a port map(a=>op2,en=>op1(1),r=>se);     U1:and4a port map(a=>op2,en=>op1(3),r=>sa);     U2:ls283 port map(o1=>sb(4 downto 1),o2=>sa,res=>result(7 downto 3));     U3:and4a port map(a=>op2,en=>op1(2),r=>sc);     U4:ls283 port map(o1=>sc,o2=>sd(4 downto 1),res=>sb);     u5:ls283 port map(o1=>sg,o2=>se,res=>sd);     u6:and4a port map(a=>op2,en=>op1(0),r=>sf);     result(0)<=sf(0);     result(1)<=sd(0);     result(2)<=sb(0);     --result(7 downto 0)<="00000000";End count;

将上面两个模块引入主程序工程的方法是:

如图所示将另外两个工程的文件夹引入主程序工程。

编译!

 

  • 上电!烧进实验箱

这个过程不在赘述,过程中如出现问题,可以参考

  • 自定义引脚如图所示:

  • 试验箱引脚组参考图():

参照上图不难看出,我使用的引脚组是

输入1:JP3(2,4,5,6)

输入2:JP4(3,4,5,6)

输出:JP6(1,2,3,4,5,6,7,8)


测试之前说说明一下:对于本实验箱:按钮输入的一组:按下0弹出1,对于推动开关输入的一组:推上1推下0,输出灯泡:亮0灭1。

测试试验箱的流程在有  详细介绍。

  • 测试

此时上排按钮表示1111,下派开关输入量为0000,结果0000 0000 灯全亮。

 

此时上排1111,下排1111,结果应为225 即 ‭11100001‬

 

此时上排1000,下排1100,结果应为3,即 0000 0011

 

当上排按钮全部按下,上排0000,无论下派为何值,结果都为0000

 

  • 结果正确,实验结束!

 

0x3四位加法器

操作和乘法器一样,不再赘述。

只做一点简要说明:

结构:halfadd-->fulladd-->adder4

贴出代码

  • halfadd
Library ieee;Use ieee.std_logic_1164.all;Entity halfadd isPort(a,b:in std_logic;     S,c:out std_logic);end halfadd;Architecture add of halfadd isbeginS<=a xor b;c<=a and b;end;
  • fulladd
Library ieee;Use ieee.std_logic_1164.all;Entity fulladd isPort(a,b,cin:in std_logic;     S,c:out std_logic);end fulladd;Architecture add of fulladd issignal m,n,k:std_logic;component halfadd isPort(a,b:in std_logic;     S,c:out std_logic);end component;beginU0:halfadd port map(a,b,m,n);U1:halfadd port map(m,cin,S,k);c<=n or k;end;
  • adder4
Library ieee;Use ieee.std_logic_1164.all;Entity adder4 isPort(a,b:in std_logic_vector(3 downto 0);      cin:in std_logic;      S:out std_logic_vector(3 downto 0);      co:out std_logic);end adder4;Architecture add of adder4 issignal c:std_logic_vector(3 downto 0);component fulladd isPort(a,b,cin:in std_logic;     S,c:out std_logic);end component;beginU0:fulladd port map(a(0),b(0),cin,S(0),c(0));U1:fulladd port map(a(1),b(1),c(0),S(1),c(1));U2:fulladd port map(a(2),b(2),c(1),S(2),c(2));U3:fulladd port map(a(3),b(3),c(2),S(3),co);end;

最后说一点:工程路径不能有中文。

 

0x4 在此给出两份文件供大家参考

VHDL 4位加法器  VHDL 4位乘法器    公共下载区

备用链接:

在试验过程中如有错误,欢迎留言,讨论,也欢迎指出我的错误。

转载地址:http://bnoen.baihongyu.com/

你可能感兴趣的文章
Ubuntu下adb无法识别android设备的解决方法
查看>>
使用U盘安装Ubuntu系统的实践小结
查看>>
编译cscope-15.8a遇到的问题与解决方案
查看>>
ubuntu下海信Hisense E920 usb连接不上的处理与adb的连接
查看>>
findbugs的ant脚本实践
查看>>
Ubuntu 12.04 安装 Subversion 1.7
查看>>
scp port 22: Connection refused
查看>>
ubuntu12.04命令行下安装RabbitVCS
查看>>
自定义cscope-index
查看>>
(ubuntu)在andorid andk工程中使用ccache加速编译速度
查看>>
android graphics system学习资料汇总
查看>>
GDB
查看>>
Oracle RAC Failover 详解
查看>>
[转载]Oracle RAC客户端连接不稳定的解决方法
查看>>
ORA RAC ORA-12545:因目标主机或对象不存在,连接失败!
查看>>
证明两节点能正常failover的sql
查看>>
oracle10g rac 报ora-12545错误的解决方案 转载
查看>>
Linux配置Xmanager
查看>>
IP地址正则表达式
查看>>
对SOAP消息头的处理
查看>>