当前位置:文档之家› 8位二进制乘法器

8位二进制乘法器

8位二进制乘EDA实验法器学号:********[2013.12.15] 班级:021151姓名:***指导老师:***一.设计要求8位二进制乘法采用移位相加的方法。

即用乘数的各位数码,从低位开始依次与被乘数相乘,每相乘一次得到的积称为部分积,将第一次(由乘数最低位与被乘数相乘)得到的部分积右移一位并与第二次得到的部分积相加,将加得的和右移一位再与第三次得到的部分积相加,再将相加的结果右移一位与第四次得到的部分积相加,直到所有的部分积都被加过一次。

例如:11010101和10010011相乘,计算过程如下:二.设计方法按照这种算法,可以得到下图所示之框图和简单流程图。

按照这种算法,可以得到下图所示之框图和简单流程图。

图中Y寄存器存放被乘数M,B寄存器存放乘数N,A累加器存放部分积。

A和Y中的数据在加法器中相加后送入A 中,而A和B相级联又构成了一个16bit的移位寄存器,当它工作于移位模式时,可以实现数据的右移。

由于乘数的每一位不是0就是1 ,对应的部分积不是0就是被乘数本身,所以实际作部分积相加这一步时,只要根据乘数的对应位判断:如该位为1 ,则将累加器中的数据加上被乘数再移位;如该位为0时,就不加被乘数而直接移位。

运算时首先将累加器A清零,并将被乘数M和乘数N分别存入寄存器Y和B,然后依据寄存器B中最右一位B0(数据N0)确定第一个部分积。

将此部分积送入A累加器以后,将A连同寄存器B右移一位,部分积的最低位被移进寄存器B的最左位,乘数的最低位N0被移出寄存器B,而乘数的次低位N1被移至寄存器B的B0位。

第二次仍然依据B0位的数据(N1)来确定第二个部分积,将部分积与累加器中的数据相加后右移一位,N1又被移出寄存器,数据N2被移到B0位置。

这样,经过8次部分积相加位的操作,完成1次乘法运算,乘数N恰好被移出寄存器B,寄存器B中保存的就是运算积的低8位数据。

移位相加的次数应用一个计数器来控制,每移位一次,计数器计一个数。

当计数器计得8个数时,发出一个信号,使电路停止操作,并输出运算结果。

三.设计过程1:8位乘法器的顶层设计P IN_17P IN_22PIN_21P IN_52P IN_53P IN_55P IN_57P IN_58P IN_59P IN_60P IN_63P IN_24P IN_9P IN_8P IN_7P IN_41P IN_30P IN_28P IN_25P IN_126P IN_129P IN_132P IN_133P IN_120P IN_121P IN_122P IN_1252:设计程序(1) 数据输入num_input 的设计该部分是在时钟信号input_clk 的作用下,记录并保存输入的8位二进制数,并存放在a 和b 中。

该模块的程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity num_input isport(data:in std_logic_vector(7 downto 0);a,b:out std_logic_vector(7 downto 0);clk:in std_logic);end num_input ;architecture behave of num_input issignal times: std_logic;beginprocess(clk)beginif clk'event and clk = '1' thenif times = '0' thentimes <= '1';a(7 downto 0) <= data(7 downto 0);elsetimes <= '0';b(7 downto 0) <= data(7 downto 0);end if;end if;end process;end behave;(2) 8位移位寄存器sreg8b的设计8位移位寄存器是在时钟信号作用下,对乘数进行加载,对数据进行移位操作,同时定义一个信号sreg8b用来装载新数据及移位后的操作数。

该模块的程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity sreg8b isport(clk:in std_logic;load:in std_logic;din:in std_logic_vector(7 downto 0);s_end:out std_logic;qb:out std_logic);end sreg8b;architecture behave of sreg8b issignal reg8:std_logic_vector(7 downto 0);signal count:std_logic_vector(3 downto 0);beginprocess(clk,load)beginif load='1' thenreg8<=din;s_end <= '0';count <= "0000";elsif clk'event and clk='1'thencount <= count + 1;if count < 7 thenreg8(6 downto 0)<=reg8(7 downto 1);elses_end <= '1';end if;end if;end process;qb<=reg8(0);end behave;(3)乘法器andarith的设计利用循环语句完成8位二进制数与1位二进制的乘法运算,将8位二进制数a从最低位到最高位与1位二进制数分别做与运算,将结果送入加法器里。

该模块程序如下:library ieee;use ieee.std_logic_1164.all;entity andarith isport(abin:in std_logic;din:in std_logic_vector(7 downto 0);dout:out std_logic_vector(7 downto 0));end andarith;architecture behave of andarith isbeginprocess(abin,din)beginfor i in 0 to 7 loopdout(i)<=din(i)and abin;end loop;end process;end behave;(4) 8位加法器adder8的设计将每次的部分积相加得到部分积之和,再与下一次的部分积相加得到新的部分积之和,没计算一次将结果送入锁存器里。

该模块程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity adder8 isport(b,a:in std_logic_vector(7 downto 0);s:out std_logic_vector(8 downto 0));end adder8;architecture behave of adder8 isbegins<='0'&a+b;end behave;(5) 16位锁存器reg16b的设计该部分接收加法器送来的部分积之和,进行处理并取高八位送给加法器进行下一次的求和,然后进行重复运算直到得到最终结果并输出。

该模块程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity reg16b isport(clk,clr,r_end:in std_logic;d:in std_logic_vector(8 downto 0);q:out std_logic_vector(15 downto 0));end reg16b;architecture behave of reg16b issignal r16s:std_logic_vector(15 downto 0);beginprocess(clk,clr,r_end)beginif clr='1'thenr16s<=(others=>'0');elsif r_end = '1' thenr16s(15 downto 0) <= r16s(15 downto 0);elsif clk'event and clk='1'thenr16s(6 downto 0)<=r16s(7 downto 1);r16s(15 downto 7)<=d;end if;end process;q<=r16s;end behave;四.波形仿真五.心得体会本次课程设计培养了我的思维,增加了思维能力,也掌握了VHDL语言里用分层次结构设计乘法器的思想和方法。

同时,在课程设计的过程中,我通过对quatus的应用,锻炼了自己的编程能力,也学会了在遇到错误的时候对程序进行调试和改进。

另外,我也懂得程序的仿真和下载到开发板是不同的,仿真没有问题,并不代表下载到开发板也没问题,因此要对程序进行测试和改进,直到出来正确而稳定的结果。

相关主题