找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5666|回复: 2
收起左侧

VHDL语言编写8位乘法器程序

[复制链接]
ID:255413 发表于 2017-11-29 21:26 | 显示全部楼层 |阅读模式
基于booth算法的有符号数乘法VHDL源代码,这是8位二进制乘法的,关于十进制转2进制的程序很简单,可以自己设置下,乘法器部分如下:library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity mp is Port ( ai,bi : in std_logic_vector(7 downto 0);        done  : out std_logic;        clk   : in std_logic;       op    : out std_logic_vector(7 downto 0)); end mp; architecture Behavioral of mp is begin    process(ai,bi,clk)        variable a,b,m : std_logic_vector( 7 downto 0);        variable cp: std_logic_vector( 1 downto 0);        variable t: std_logic ;        variable counter: integer;        begin           if clk'event and clk='1' then            counter:=0;             t:='0';             a:=ai;             b:=bi;             m:="00000000";             cp:=b(0)&'0';             done<='0'; --是否完成计算            while counter<8 loop                  case cp is                  when "10"=> m:=m-a;                  when "01"=> m:=m+a;                  when others=>m:=m;             end case;             t:=b(0);             b:=m(0)&b(7 downto 1);            m:=m(7)&m(7 downto 1);             cp:=b(0)&t;             counter:=counter+1;             end loop;          op<= m&b;          done<='1';        end if;    end process; end Behavioral; 然后下面这个是加法器树乘法器的源代码,也是8位2进制乘法源码,如果这两种方法还不够就MMM我好了library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity ywxj_multipier isport(clk: in std_logic;       a: in std_logic_vector(7 downto 0);--乘数       b: in std_logic_vector(7 downto 0);--被乘数       y: out std_logic_vector(15 downto 0));--输出end ywxj_multipier;architecture rtl of ywxj_multipier isbeginp1: process(clk)    variable n0,n1,n2,n3,n4,n5,n6,n7: std_logic_vector(15 downto 0);    variable m: std_logic_vector(7 downto 0);    begin    m:="00000000";      if clk'event and clk='1' then         if a(0)<='0' then         n0:="0000000000000000";         else         n0:=m&b;         end if;         if a(1)<='0' then         n1:="0000000000000000";         else         n1:=m(7 downto 1)&b&m(0);         end if;         if a(2)<='0' then         n2:="0000000000000000";         else         n2:=m(7 downto 2)&b&m(1 downto 0);         end if;         if a(3)<='0' then         n3:="0000000000000000";         else         n3:=m(7 downto 3)&b&m(2 downto 0);         end if;         if a(4)<='0' then         n4:="0000000000000000";         else         n4:=m(7 downto 4)&b&m(3 downto 0);         end if;         if a(5)<='0' then         n5:="0000000000000000";         else         n5:=m(7 downto 5)&b&m(4 downto 0);         end if;         if a(6)<='0' then         n6:="0000000000000000";         else         n6:=m(7 downto 6)&b&m(5 downto 0);         end if;         if a(7)<='0' then         n7:="0000000000000000";         else         n7:=m(7)&b&m(6 downto 0);         end if;         y<=n0+n1+n2+n3+n4+n5+n6+n7;   end if; end process p1;end rtl;

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:1 发表于 2017-12-6 11:44 | 显示全部楼层
给大家分享一个文件:
八位乘法器VHDL语言实现。使用的工具的ISE7.1.rar (2.18 KB, 下载次数: 15)
回复

使用道具 举报

ID:388050 发表于 2018-8-20 11:11 | 显示全部楼层
module_line_one,MODULE_LINE_MID,MODULE_LINE_LAST这几个元件的代码在附件里吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表