当前位置:   article > 正文

Quartus II 实验 (二)——VHDL 4位加法器和4位乘法器_四位乘法器vhdl

四位乘法器vhdl

0x1 前言 

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

关于我所使用的试验箱DICE-E213的部分介绍请参照 Quartus II 实验 (一)——软件和试验箱DICE-E213的基本说明 

 

0x2 四位乘法器

  • 首先说明目录结构:

|

|-- and4a

|-- ls283

|-- mul4p  

  • 二进制加法过程

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

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

 

  • and4a

  1. Library ieee;
  2. Use ieee.std_logic_1164.all;
  3. Use ieee.std_logic_unsigned.all;
  4. Entity and4a is
  5. Port(a:in std_logic_vector(3 downto 0);
  6. en:in std_logic;
  7. r:out std_logic_vector(3 downto 0));
  8. End and4a;
  9. Architecture behave of and4a is
  10. Begin
  11. Process(en,a(3 downto 0))
  12. Begin
  13. If (en='1') then
  14. r<=a;
  15. Else
  16. r<="0000";
  17. End if;
  18. End process;
  19. End behave;
  • ls283

  1. Library ieee;
  2. Use ieee.std_logic_1164.all;
  3. Use ieee.std_logic_unsigned.all;
  4. Entity ls283 is
  5. Port (o1,o2:in std_logic_vector(3 downto 0);
  6. res:out std_logic_vector(4 downto 0));
  7. End ls283;
  8. Architecture behave of ls283 is
  9. Begin
  10. Process(o1,o2)
  11. Begin
  12. res<=('0'&o1)+('0'&o2);
  13. End process;
  14. End behave;
  • mul4p

这部分是主程序

  1. Library ieee;
  2. Use ieee.std_logic_1164.all;
  3. Use ieee.std_logic_unsigned.all;
  4. Entity mul4p is
  5. Port (op1,op2:in std_logic_vector(3 downto 0);
  6. result:out std_logic_vector(7 downto 0));
  7. End mul4p;
  8. Architecture count of mul4p is
  9. component and4a port (a:in std_logic_vector(3 downto 0);
  10. en:in std_logic;
  11. r:out std_logic_vector(3 downto 0));
  12. End component;
  13. Component ls283 port (o1,o2:in std_logic_vector(3 downto 0);
  14. res:out std_logic_vector(4 downto 0));
  15. End component;
  16. Signal sa:std_logic_vector(3 downto 0);
  17. Signal sb:std_logic_vector(4 downto 0);
  18. Signal sc:std_logic_vector(3 downto 0);
  19. Signal sd:std_logic_vector(4 downto 0);
  20. Signal se:std_logic_vector(3 downto 0);
  21. Signal sf:std_logic_vector(3 downto 0);
  22. Signal sg:std_logic_vector(3 downto 0);
  23. --signal tmp1:std_logic;
  24. Begin
  25. sg<=('0'&sf (3 downto 1));
  26. --tmp1<=op1(1);
  27. u0:and4a port map(a=>op2,en=>op1(1),r=>se);
  28. U1:and4a port map(a=>op2,en=>op1(3),r=>sa);
  29. U2:ls283 port map(o1=>sb(4 downto 1),o2=>sa,res=>result(7 downto 3));
  30. U3:and4a port map(a=>op2,en=>op1(2),r=>sc);
  31. U4:ls283 port map(o1=>sc,o2=>sd(4 downto 1),res=>sb);
  32. u5:ls283 port map(o1=>sg,o2=>se,res=>sd);
  33. u6:and4a port map(a=>op2,en=>op1(0),r=>sf);
  34. result(0)<=sf(0);
  35. result(1)<=sd(0);
  36. result(2)<=sb(0);
  37. --result(7 downto 0)<="00000000";
  38. End count;

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

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

编译!

 

  • 上电!烧进实验箱

这个过程不在赘述,过程中如出现问题,可以参考 Quartus II 实验 (一)——软件和试验箱DICE-E213的基本说明

  • 自定义引脚如图所示:

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

输入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。

测试试验箱的流程在有 Quartus II 实验 (一)——软件和试验箱DICE-E213的基本说明 详细介绍。

  • 测试

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

 

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

 

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

 

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

 

  • 结果正确,实验结束!

 

0x3四位加法器

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

只做一点简要说明:

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

贴出代码

  • halfadd
  1. Library ieee;
  2. Use ieee.std_logic_1164.all;
  3. Entity halfadd is
  4. Port(a,b:in std_logic;
  5. S,c:out std_logic);
  6. end halfadd;
  7. Architecture add of halfadd is
  8. begin
  9. S<=a xor b;
  10. c<=a and b;
  11. end;
  • fulladd
  1. Library ieee;
  2. Use ieee.std_logic_1164.all;
  3. Entity fulladd is
  4. Port(a,b,cin:in std_logic;
  5. S,c:out std_logic);
  6. end fulladd;
  7. Architecture add of fulladd is
  8. signal m,n,k:std_logic;
  9. component halfadd is
  10. Port(a,b:in std_logic;
  11. S,c:out std_logic);
  12. end component;
  13. begin
  14. U0:halfadd port map(a,b,m,n);
  15. U1:halfadd port map(m,cin,S,k);
  16. c<=n or k;
  17. end;
  • adder4
  1. Library ieee;
  2. Use ieee.std_logic_1164.all;
  3. Entity adder4 is
  4. Port(a,b:in std_logic_vector(3 downto 0);
  5. cin:in std_logic;
  6. S:out std_logic_vector(3 downto 0);
  7. co:out std_logic);
  8. end adder4;
  9. Architecture add of adder4 is
  10. signal c:std_logic_vector(3 downto 0);
  11. component fulladd is
  12. Port(a,b,cin:in std_logic;
  13. S,c:out std_logic);
  14. end component;
  15. begin
  16. U0:fulladd port map(a(0),b(0),cin,S(0),c(0));
  17. U1:fulladd port map(a(1),b(1),c(0),S(1),c(1));
  18. U2:fulladd port map(a(2),b(2),c(1),S(2),c(2));
  19. U3:fulladd port map(a(3),b(3),c(2),S(3),co);
  20. end;

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

 

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

VHDL 4位加法器  VHDL 4位乘法器  http://sudo.ys168.com/  公共下载区

备用链接:https://download.csdn.net/download/qq_41420747/11248001

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/707935
推荐阅读
相关标签
  

闽ICP备14008679号