VHDL的乘法器设计——数字电路课程设计

合集下载

VHDL的乘法器设计——数字电路课程设计

VHDL的乘法器设计——数字电路课程设计
cout=>e,s=>s4(2)); u11:full_adder port map (a=>d3(3),b=>d3(4),cin=>e,
cout=>c4,s=>s4(1));
------------------------------last u12:full_adder port map (a=>d4(1),b=>d4(2),cin=>d4(3),
【第二章】:设计思路及方案 算法结构(无符号)
由上图可见,乘法的运算最终是加法的运算,两个 4BIT 输入,输出为 7BIT。 模块一、半加器:单比特输入相加,
模块二、全加器:由两个半加器组成,有一个进位输入,
模块三、进位保留加法器:
3
最终程序结构图
流水设计的原理:在前向割集上加入四级流水
图一 图二
elsif clk'event and clk='1' then
--------------------------------------first d1(1)<= x(1); d1(2)<= x(2); d1(3)<= x(3);
7
d1(4)<= x(4); d1(5)<= x(5); d1(6)<= x(6); d1(7)<=c1(1) ; d1(8)<=s1(1); d1(9)<= x(9); d1(10)<=x(10); d1(11)<=c1(2); d1(12)<=s1(2); d1(13)<=x(13); d1(14)<=c1(3) ; d1(15)<=s1(3) ; d1(16)<=x(16);

原码一位乘法器设计实验报告

原码一位乘法器设计实验报告

原码一位乘法器设计实验报告一位乘法器设计实验报告本次实验的目的是设计一个1位乘法器,使用VHDL语言在FPGA平台上进行编程,以模拟数字系统中常用的数字乘法操作。

(1)实验介绍本次实验采用FPGA对1位乘法器进行设计,通过综合语言VHDL对1位乘法器进行编程,实现乘法操作,考核我们所学习到的技能,及其在数字电路中的运用。

(2)原理1位乘法器(One-bit Multiplier)主要包括一个数据输入端A,输入一位A;B输入端,输入一位B;两个控制端,乘法指令和正负指令;产生和端为Cout,乘法结果输出端为Dout。

1位乘法器的功能是:如果A、B都为0时,整个乘法器保持空闲,如果A>0或者 B>0,就会开始乘法运算,Cout为A与B的AND运算结果,Dout=A*B,即当B=1时,Dout=A;当B=0时,Dout=0。

(3)实验流程(1)设计多位乘法器的功能模块,完成模块之间的接口描述;(2)设计1位乘法器的VHDL代码,其中包括输入、输出、控制部分;(3)利用Xilinx ISE 14.6完成编译,查看综合错误情况;(4)绘制电路图,添加模块;(5)进行仿真测试,将模块内各部分功能输入实际值,验证运算正确性;(6)在DE2开发板上运行代码,上传新的程序,查看实际运行情况,确认乘法器可以正确工作;(7)验证结果,完成整个乘法器的设计。

(4)实验结果本次实验通过编写VHDL语言,绘制电路图,仿真测试,烧写程序等步骤,设计出一位乘法器,实现了正确乘法运算功能,实验结果如下图所示:此外,实验中使用的FPGA开发板的硬件设计采用Cyclone ll,有良好的性能和可编程性,在编程和复杂数字电路处理领域有很强的优势。

(5)总结本次实验通过实验,熟悉了1位乘法器的结构及其工作原理,掌握综合语言VHDL和FPGA编程技术,掌握了数字电路设计。

最后,本次实验完成了乘法器的设计,检验结果满足预期,获得有意义的实验教训,实现了实验目标。

数字系统设计VHDL课设报告

数字系统设计VHDL课设报告
1)IEEE 754转定点数
模块名:ieee7542point(clk,rst_n,inp,pointdata);
出入参数说明:clk:时钟。
rst_n:异步复位信号输入。
Inp:三十二位浮点数输入,规定为ieee754格式,切指数范围为0——127,因为为了配合之前cordic算法的±90的输入。
-30度(14’h3fbd)
-0.5000(0x1fc0)
0.8750(0x0070)
90度(14’h00C9)
0.9843(0x7e)
0.0078(0x0001)
-90度(14’h3f37)
-1.000(0x1f80)
0.0000(0x0000)
结果分析:设计中采用流水线结构,第九个时钟以后,每个时钟都会产生一个结果,是一种高速度的运算器,从综合的结果看,运算器的运算速度可以达到200M以上,满足一般工程应用的需求。从采样出来的几组经典数据来看,也能够充分验证该运算器的精度,同时证明该设计的合理性和正确性。
clk:时钟信号输入端,一位。
rst_n:异步复位输入端,一位。
inp:十四位定点数输入端,采用补码形式输入,输入范围±90度,采用弧度形式输入。
res_sin,res_cos:十三位输出端,也是带符号补码形式。
所有过程变量:均未补码形式。
六,实验结果
本设计采用SynplifyPro 9.6.2进行综合,采用modelsim6.5进行仿真,仿真结果如下所示:
(1)、cordic算法原理
CORDIC算法包含圆周系统,线性系统,双曲系统三种旋转系统。本文仅以圆周系统推导如下。该系统完成的是一个平面坐标旋转如图1所示,可以看出,将向量( Xi, Yi)旋转θ角,得到一个新的向量( Xi, Yi) ,那么有:

八位乘法器VHDL及功能模块说明

八位乘法器VHDL及功能模块说明

EDA课程设计报告实验名称:八位乘法器目录一.引言1.1 EDA技术的概念••1.2 EDA技术的特点••1.3 EDA设计流程••1.4 VHDL介绍••二.八位乘法器的设计要求与设计思路••2.1 设计目的••2.2 设计要求••三.八位乘法器的综合设计••3.1 八位乘法器功能••3.2 八位乘法器设计方案••3.3 八位乘法器实体设计••3.4 八位乘法器VHDL设计••3. 5八位乘法器仿真图形••心得体会••参考文献••一、引言1.1 EDA技术的概念EDA是电子设计自动化(Electronic Design Automation)的缩写,在20世纪90年代初从计算机辅助设计(CAD)、计算机辅助制造(CAM)、计算机辅助测试(CAT)和计算机辅助工程(CAE)的概念发展而来的。

EDA技术就是以计算机为工具,设计者在EDA软件平台上,用硬件描述语言HDL 完成设计文件,然后由计算机自动地完成逻辑编译、化简、分割、综合、优化、布局、布线和仿真,直至对于特定目标芯片的适配编译、逻辑映射和编程下载等工作。

1.2 EDA技术的特点利用EDA技术进行电子系统的设计,具有以下几个特点:①用软件的方式设计硬件;②用软件方式设计的系统到硬件系统的转换是由有关的开发软件自动完成的;③设计过程中可用有关软件进行各种仿真;④系统可现场编程,在线升级;⑤整个系统可集成在一个芯片上,体积小、功耗低、可靠性高。

因此,EDA技术是现代电子设计的发展趋势。

1.3 EDA设计流程典型的EDA设计流程如下:1、文本/原理图编辑与修改。

首先利用EDA工具的文本或图形编辑器将设计者的设计意图用文本或图形方式表达出来。

2、编译。

完成设计描述后即可通过编译器进行排错编译,变成特定的文本格式,为下一步的综合做准备。

3、综合。

将软件设计与硬件的可实现性挂钩,是将软件转化为硬件电路的关键步骤。

4、行为仿真和功能仿真。

利用产生的网表文件进行功能仿真,以便了解设计描述与设计意图的一致性。

VHDL移位相加8位硬件乘法器电路设计

VHDL移位相加8位硬件乘法器电路设计

课程名称:EDA技术实验实验名称:移位相加8位硬件乘法器电路设计一、实验目的:1、学习移位相加8位硬件乘法器电路设计;2、进一步提高学生应用EDA技术进行项目设计的能力。

二、实验原理纯组合逻辑结构构成的乘法器虽然工作速度比较快,但过于占用硬件资源,难以实现宽位乘法器;基于PLD器件外接ROM九九表的乘法器则无法构成单片系统,也不实用。

本实验由8位加法器构成的以时序逻辑方式设计锝位乘法器,具有一定的实用价值。

其原理是:乘法通过逐位相加原理来实现,从被乘数的最低位开始,若为1,则乘数左移后与上一次的和相加;若为0,左移后以全0相加,直至被乘数的最高位。

三、实验内容1、打开Q 软件,新建VHDL程序输入文件,用VHDL语言设计乘法器的各个模块:LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY SREG8B ISPORT ( CLK : IN STD_LOGIC;LOAD : IN STD_LOGIC;DIN : IN STD_LOGIC_VECTOR(7 DOWNTO 0);QB : OUT STD_LOGIC );END SREG8B;ARCHITECTURE behav OF SREG8B ISSIGNAL REG8 : STD_LOGIC_VECTOR(7 DOWNTO 0);BEGINPROCESS (CLK,LOAD)BEGINIF LOAD = '1' THEN REG8 <= DIN;ELSIF CLK'EVENT AND CLK = '1' THENREG8(6 DOWNTO 0) <= REG8(7 DOWNTO 1);END IF;END PROCESS;QB <= REG8(0);END behav;图1.1 8位右移寄存器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 behav OF ADDER8 ISBEGINS <= '0'&A+B;END behav;图1.2 8位加法器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 ANDRITH;ARCHITECTURE behav OF ANDARITH ISBEGINPROCESS(ABIN,DIN)BEGINFOR I IN 0 TO 7 LOOPDOUT(I) <= DIN(I) AND ABIN;END LOOP;END PROCESS;END behav;图1.3 选通与门模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY REG16B ISPORT ( CLK,CLR : IN STD_LOGIC;D : IN STD_LOGIC_VECTOR(8 DOWNTO 0);Q : OUT STD_LOGIC_VECTOR(15 DOWNTO 0)); END REG16B;ARCHITECTURE behav OF REG16B ISSIGNAL R16S :STD_LOGIC_VECTOR(15 DOWNTO 0); BEGINPROCESS(CLK,CLR)BEGINIF CLR = '1' THEN R16S <= (OTHERS =>'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 behav;图1.4 16位锁存器2、对各个模块进行编译并打包成电路元件,如上图1所示。

基于VHDL语言的乘法器的设计

基于VHDL语言的乘法器的设计

利用VHDL設計乘法器Implement of Multiplier by Using VHDL許地申Dih-Shen Hsu中華技術學院電機系副教授Associate ProfessorDepartment of Electrical EngineeringChina Institute of Technology摘 要在計算機結構裡加,減,乘,除是常被用到的運算,本文提出以非常高速積體電路硬體描述語言(VHDL)來描述硬體,說明如何將兩個運算元作相乘的運算。

我們首先以無號數整數做乘法運算來說明其原理,設計其電路結構。

其實在VHDL 程式中,我們更可以載入STD_LOGIC_ARITH與STD_LOGIC_UNSIGNED元件盒之後,直接進行乘法運算,既簡單又容易擴充。

最後,我們將以4-bit X 4-bit 的例子來做電路描述、電路合成、電路模擬並以七段顯示器將其結果顯示出來。

關鍵字:非常高速積體電路硬體描述語言、電路描述、電路合成、電路模擬AbstractWe have known operation that perform addition, subtraction, multiplication, and division. In this paper we are presented primarily to describe hardware using by VHDL. We can explain how multiplication may be performed for two operand. Multiplication of unsigned numbers illustrates the main issues involved in the design of multiplier circuit. In fact, after the STD_LOGIC_ARITH and STD_LOGIC_UNSIGNED packages were added to the VHDL program, it became not only simple but also easy to extended. Next, consider a 4 x 4 example to circuit description, circuit synthesis, and circuit simulation by using VHDL. Finally, this approach can also be displayed by 7-segment.Keyword : VHDL , circuit description , circuit synthesis, circuit simulation壹.簡介VHDL是Very High Speed Integrated Circuit Hardware Description Language 的英文縮寫。

乘法器课程设计

乘法器课程设计

摘要:基于VHDL的数字系统设计具有设计技术齐全、方法灵活、支持广泛等优点,同时也是EDA技术的重要组成部分.文章用VHDL语言设计了左移法和进位节省法实现的两种组合乘法器,通过功能仿真,对两种乘法器的性能进行了比较,从而得知后者的传输延迟时间小,即速度较快.通过设计实例,介绍了利用VHDL语言进行数字系统设计的方法.关键词:VHDL语言左移法进位节省法Abstract:Digital system design based on VHDL has complete design techniques, methods, the advantages of flexible and wide support, at the same time also is the important component of the EDA technology. The article using VHDL language to design the left shift method and carry save method to realize the combination of two kinds of multiplier, through the function simulation, compares the performance of the two kinds of multiplier, which the latter's small transmission delay time, namely fast. Through the design example, introduced the method of using VHDL language to design digital system.Keywords:VHDL language ,left shift method ,carry save method目录1.前言 (1)2.系统设计总述 (2)2.1 设计要求 (2)2.2系统组成.............................................. ..22.2.1 乘法器电路基本原理.............................................................32.2.2 输入数据的获得............................................................. (3)2.2.3 数据的选择输入和输出控制 (3)3.设计步骤 (4)3.1整体原理框图: (4)3.2乘法器整体电路原理图: (5)3.3输入模块: (5)3.4运算模块: (5)3.5显示控制模块: (6)3.6显示模块: (7)4.整体仿真┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉105.调试中遇到的问题及解决的方法┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉11 6.设计总结┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉12 7.参考文献┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉13附录:程序代码┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉141.前言电子EDA技术发展迅猛,逐渐在教学、科研、产品设计与制造等各方面都发挥着巨大的作用。

9X9乘法表VHDL

9X9乘法表VHDL

9*9乘法器的VHDL的设计1 设计任务制作一个9*9乘法器2 设计说明输入两个四位二进制信号a,b分别作为被乘数和乘数,以8421bcd码编号,输入一个一位信号oc作为控制信号;输出两个四位二进制信号c,d分别作为结果的十位和个位,以8421bcd码编号。

3 设计结果3.1 原理图图1 原理图3.2 信号表a:被乘数,用4位二进制8421bcd码表示;b:乘数,用4位二进制8421bcd码表示;oc:控制信号;c:结果的十位,用4位二进制8421bcd码表示;d:结果的个位,用4位二进制8421bcd码表示;图2 信号表3.3仿真结果图3 oc、a、b分别为0、2、8和0、4、3时结果图4 oc、a、b分别为1、2、8和1、4、3时结果图5 oc、a、b分别为0、10、8和0、4、11时结果3.4 电路图图6 原理图3.5 程序清单LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY mul9 ISPORT (oc: IN std_logic;a,b: IN std_logic_vector (3 downto 0);c,d: OUT std_logic_vector(3 downto 0));END;ARCHITECTURE one OF mul9 ISBEGINPROCESS(a,b)BEGINIF(oc = '1') THENIF(a = "0001") THENCASE b ISWHEN "0001" =>c <= "0000"; d <= "0001"; WHEN "0010" =>c <= "0000"; d <= "0010";WHEN "0011" =>c <= "0000"; d <= "0011"; WHEN "0100" =>c <= "0000"; d <= "0100";WHEN "0101" =>c <= "0000"; d <= "0101"; WHEN "0110" =>c <= "0000"; d <= "0110";WHEN "0111" =>c <= "0000"; d <= "0111"; WHEN "1000" =>c <= "0000"; d <= "1000";WHEN "1001" =>c <= "0000"; d <= "1001"; WHEN OTHERS =>c <= "0000"; d <= "0000";END CASE;CASE b ISWHEN "0001" =>c <= "0000"; d <= "0010"; WHEN "0010" =>c <= "0000"; d <= "0100";WHEN "0011" =>c <= "0000"; d <= "0101"; WHEN "0100" =>c <= "0000"; d <= "1000";WHEN "0101" =>c <= "0001"; d <= "0000"; WHEN "0110" =>c <= "0001"; d <= "0010";WHEN "0111" =>c <= "0001"; d <= "0100"; WHEN "1000" =>c <= "0001"; d <= "0110";WHEN "1001" =>c <= "0001"; d <= "1000"; WHEN OTHERS =>c <= "0000"; d <= "0000";END CASE;ELSIF(a = "0011") THENCASE b ISWHEN "0001" =>c <= "0000"; d <= "0101"; WHEN "0010" =>c <= "0000"; d <= "0110";WHEN "0011" =>c <= "0000"; d <= "1001"; WHEN "0100" =>c <= "0001"; d <= "0010";WHEN "0101" =>c <= "0001"; d <= "0101"; WHEN "0110" =>c <= "0001"; d <= "1000";WHEN "0111" =>c <= "0010"; d <= "0001"; WHEN "1000" =>c <= "0010"; d <= "0100";WHEN "1001" =>c <= "0010"; d <= "0111"; WHEN OTHERS =>c <= "0000"; d <= "0000";END CASE;CASE b ISWHEN "0001" =>c <= "0000"; d <= "0100"; WHEN "0010" =>c <= "0000"; d <= "1000";WHEN "0011" =>c <= "0001"; d <= "0010"; WHEN "0100" =>c <= "0001"; d <= "0110";WHEN "0101" =>c <= "0010"; d <= "0000"; WHEN "0110" =>c <= "0010"; d <= "0100";WHEN "0111" =>c <= "0010"; d <= "1000"; WHEN "1000" =>c <= "0011"; d <= "0010";WHEN "1001" =>c <= "0011"; d <= "0101"; WHEN OTHERS =>c <= "0000"; d <= "0000";END CASE;ELSIF(a = "0101") THENCASE b ISWHEN "0001" =>c <= "0000"; d <= "0101"; WHEN "0010" =>c <= "0001"; d <= "0000";WHEN "0011" =>c <= "0001"; d <= "0101"; WHEN "0100" =>c <= "0010"; d <= "0000";WHEN "0101" =>c <= "0010"; d <= "0101"; WHEN "0110" =>c <= "0011"; d <= "0000";WHEN "0111" =>c <= "0011"; d <= "0101"; WHEN "1000" =>c <= "0100"; d <= "0000";WHEN "1001" =>c <= "0100"; d <= "0101"; WHEN OTHERS =>c <= "0000"; d <= "0000";END CASE;CASE b ISWHEN "0001" =>c <= "0000"; d <= "0110"; WHEN "0010" =>c <= "0001"; d <= "0010";WHEN "0011" =>c <= "0001"; d <= "1000"; WHEN "0100" =>c <= "0010"; d <= "0100";WHEN "0101" =>c <= "0011"; d <= "0000"; WHEN "0110" =>c <= "0011"; d <= "0110";WHEN "0111" =>c <= "0100"; d <= "0010"; WHEN "1000" =>c <= "0100"; d <= "1000";WHEN "1001" =>c <= "0101"; d <= "0100"; WHEN OTHERS =>c <= "0000"; d <= "0000";END CASE;ELSIF(a = "0111") THENCASE b ISWHEN "0001" =>c <= "0000"; d <= "0111"; WHEN "0010" =>c <= "0001"; d <= "0100";WHEN "0011" =>c <= "0010"; d <= "0001"; WHEN "0100" =>c <= "0010"; d <= "1000";WHEN "0101" =>c <= "0011"; d <= "0101"; WHEN "0110" =>c <= "0100"; d <= "0010";WHEN "0111" =>c <= "0100"; d <= "1001"; WHEN "1000" =>c <= "0101"; d <= "0110";WHEN "1001" =>c <= "0110"; d <= "0011"; WHEN OTHERS =>c <= "0000"; d <= "0000";END CASE;CASE b ISWHEN "0001" =>c <= "0000"; d <= "1000"; WHEN "0010" =>c <= "0001"; d <= "0110";WHEN "0011" =>c <= "0010"; d <= "0110"; WHEN "0100" =>c <= "0011"; d <= "0010";WHEN "0101" =>c <= "0100"; d <= "0000"; WHEN "0110" =>c <= "0100"; d <= "1000";WHEN "0111" =>c <= "0101"; d <= "0110"; WHEN "1000" =>c <= "0110"; d <= "0100";WHEN "1001" =>c <= "0111"; d <= "0010"; WHEN OTHERS =>c <= "0000"; d <= "0000";END CASE;ELSIF(a = "1001") THENCASE b ISWHEN "0001" =>c <= "0000"; d <= "1001"; WHEN "0010" =>c <= "0001"; d <= "1000";WHEN "0011" =>c <= "0010"; d <= "0111"; WHEN "0100" =>c <= "0010"; d <= "0110";WHEN "0101" =>c <= "0100"; d <= "0101"; WHEN "0110" =>c <= "0101"; d <= "0100";WHEN "0111" =>c <= "0101"; d <= "0110"; WHEN "1000" =>c <= "0111"; d <= "0010";WHEN "1001" =>c <= "1000"; d <= "0001"; WHEN OTHERS =>c <= "0000"; d <= "0000";END CASE;ELSEc <= "0000";d <= "0000";END IF;ELSE c <= "0000"; d <= "0000";END IF;END PROCESS;END one;4 实验总结通过这次课程设计,我进一步加深了对电子设计自动化的了解。

vhdl 四位流水线乘法器

vhdl 四位流水线乘法器

实验二四位流水线乘法器一、实验目的1.了解四位并行乘法器的原理。

2.了解四位并行乘法器的设计思想和流水线的实现方法。

3.掌握用VHDL 语言实现基本二进制运算的方法。

二、实验内容与要求通过开关和键盘输入两组4BIT的二进制数据,按照二进制加法器原理进行加和,求出和及进位,并通过LED显示灯输出显示,完成编译、综合、适配、仿真、实验箱上的硬件测试。

三、实验原理流水线结构的并行乘法器的最大有点就是速度快,尤其实在连续输入的乘法器中,可以达到近乎单周期的运算速度。

流水线乘法器是组合逻辑电路实现无符号数乘法的方法上发展而来的。

其关键是在组合逻辑电路的基础上插入寄存器。

假如有被乘数A 和乘数B,首先用A 与B 的最低位相乘得到S1,然后再把A 左移1 位与B 的第2 位相乘得到S2,再将A 左移3 位与B 的第三位相乘得到S3,依此类推,直到把B 的所有位都乘完为止,然后再把乘得的结果S1、S2、S3……相加即得到相乘的结果。

需要注意的是,具体实现乘法器是,并不是真正的去乘,而是利用简单的判断去实现,举个简单的例子。

假如A 左移n 位后与B 的第n 位相乘,如果B 的这位为‘1’,那么相乘的中间结果就是A 左移n 位后的结果,否则如果B 的这位为‘0’,那么就直接让相乘的中间结果为0 即可。

带B 的所有位相乘结束后,把所有的中间结果相加即得到A 与B 相乘的结果。

在此基础上插入寄存器即可实现流水线乘法器。

四、实验平台(1)硬件:计算机、GX-SOC/SOPC-DEV-LABCycloneII EP2C35F672C8核心板(2)软件:Quartus II软件PIN_AF8 DATAOUT[4] LED4PIN_AE7 DATAOUT[5] LED5PIN_AF7 DATAOUT[6] LED6PIN_AA11 DATAOUT[7] LED7PIN_AE21 BCD[0] 数码管DP4BPIN_AB20 BCD[1]PIN_AC20 BCD[2]PIN_AF20 BCD[3]PIN_AE20 BCD[4] 数码管DP5BPIN_AD19 BCD[5]PIN_AC19 BCD[6]PIN_AA17 BCD[7]PIN_AA18 BCD[8] 数码管DP6BPIN_W17 BCD[9]PIN_V17 BCD[10]PIN_AB18 BCD[11]六、仿真截图七、硬件实现八、程序代码1---clkgen.vhdlibrary IEEE;-- 1HZuse IEEE.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity clkgen isport (CLK : in std_logic;CLK1HZ: out std_logic);end entity;architecture clk_arch of clkgen issignal COUNT : integer range 0 to 50000000; --50MHZ -->1hz begin -- 50M/1=50000000 PROCESS(CLK)BEGINif clk'event and clk='1' thenIF COUNT= 50000000 thenCOUNT<=0;ELSE COUNT<=COUNT+1;END IF;END IF;END PROCESS;PROCESS(COUNT)BEGINIF COUNT= 5000000 THEN -- 1HZCLK1HZ<='1';ELSE CLK1HZ<='0';END IF;END PROCESS;end architecture;2—BCD-- 输出控制模块,把乘法器的输出转换成BCD码在数码管上显示、-- SCKZ.VHDlibrary IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity BIN2BCD isport ( DIN: in std_logic_vector(7 downto 0); ---The input 8bit binaryBCDOUT: out std_logic_vector(11 downto 0)--输出显示, 已转换成BCD码);end entity;architecture arch of BIN2BCD issignal data2,data3,data4 :std_logic_vector(9 downto 0);-- 输出数据缓存signal hundred,ten,unit:std_logic_vector(3 downto 0);--signal bcdbuffer:std_logic_vector(11 downto 0);---2'1111_1001_11=999beginBCDOUT<= bcdbuffer;bcdbuffer(11 downto 8)<=hundred;bcdbuffer(7 downto 4)<=ten;bcdbuffer(3 downto 0)<=unit;get_hundred_value:process(data2)beginDA TA2<="00"&DIN;---get hundred valueif data2>=900 thenhundred<="1001";--9data3<=data2-900;elsif data2>=800 thenhundred<="1000";--8data3<=data2-500;elsif data2>=700 thenhundred<="0111";--7data3<=data2-700;elsif data2>=600 thenhundred<="0110";--6data3<=data2-600;elsif data2>=500 thenhundred<="0101";--5data3<=data2-500;elsif data2>=400 thenhundred<="0100";--4data3<=data2-400;elsif data2>=300 thenhundred<="0011";--3data3<=data2-300;elsif data2>=200 thenhundred<="0010";--2data3<=data2-200;elsif data2>=100 thenhundred<="0001";--1data3<=data2-100;else data3<=data2;hundred<="0000";end if;end process; ---get_thousand_valueget_tens_value:process(data3) begin---get tens placeif data3>=90 thenten<="1001";--9data4<=data3-90;elsif data3>=80 thenten<="1000";--8data4<=data3-50;elsif data3>=70 thenten<="0111";--7data4<=data3-70;elsif data3>=60 thenten<="0110";--6data4<=data3-60;elsif data3>=50 thenten<="0101";--5data4<=data3-50;elsif data3>=40 thenten<="0100";--4data4<=data3-40;elsif data3>=30 thenten<="0011";--3data4<=data3-30;elsif data3>=20 thenten<="0010";--2data4<=data3-20;elsif data3>=10 thenten<="0001";--1data4<=data3-10;else data4<=data3;ten<="0000";end if;end process; ---get_ten_valueget_unit_value:process(data4)begin--unit's orderif (data4>0) thenunit<=data4(3 downto 0);else unit<="0000";end if;end process;end arch;3 multi4b --------------------------------------------------------------------------------/ -- DESCRIPTION : Signed mulitplier:-- AIN (A) input width : 4-- BIN (B) input width : 4-- Q (data_out) output width : 8-- 并行流水乘法器--------------------------------------------------------------------------------/--10 × 9 = 90-- 1 0 1 0-- 1 0 0 1 =-- --------------- 1 0 1 0-- 0 0 0 0 --partial products-- 0 0 0 0-- 1 0 1 0-- -------------------- 1 0 1 1 0 1 0--parallel : process all the inputs at the same time--pipeline : use several stages with registers to implement it----关键思想,插入寄存器library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity multi4b isport ( CLK: in STD_LOGIC; ---system clockAIN: in STD_LOGIC_VECTOR (3 downto 0); ---one inputBIN: in STD_LOGIC_VECTOR (3 downto 0);-- the other inputdata_out: out STD_LOGIC_VECTOR (7 downto 0)---the result ---make sure the biggest value ,i,e. 1111x1111=1110_0001 can be held in the register );end multi4b;architecture multi_arch of multi4b issignal A,B :std_logic_vector(3 downto 0); --input register---registers to hold the result of the first processing---registers added to make use of pipeline, the 1st stagesignal A_MULT_B0: STD_LOGIC_VECTOR (3 downto 0);signal A_MULT_B1: STD_LOGIC_VECTOR (3 downto 0);signal A_MULT_B2: STD_LOGIC_VECTOR (3 downto 0);signal A_MULT_B3: STD_LOGIC_VECTOR (3 downto 0);---register to hold the result of the multipliersignal C_TEMP : STD_LOGIC_VECTOR (7 downto 0);beginPROCESS(CLK,AIN,BIN)beginif CLK'EVENT AND CLK='1' THEN-- multiplier operand inputs are registeredA<= AIN;B<= BIN;-----------------Fist stage of the multiplier------------------here we get the axb(0),axb(1),axb(2),axb(3),i.e.partial products---put them into the responding registersA_MULT_B0(0) <= A (0) and B (0);----- multi 1 , get the a(0) and b(0), & put it into the register A_MULT_B0(0)A_MULT_B0(1) <= A (1) and B (0);A_MULT_B0(2) <= A (2) and B (0);A_MULT_B0(3) <= A (3) and B (0);--10 × 9 = 90-- 1 0 1 0-- 1 0 0 1 =-- --------------- 0 0 0 0 1 0 1 0-- 0 0 0 0 0 0 0 0 --partial products-- 0 0 0 0-- 1 0 1 0-- -------------------- 1 0 1 1 0 1 0A_MULT_B1(0) <= A (0) and B (1);A_MULT_B1(1) <= A (1) and B (1);A_MULT_B1(2) <= A (2) and B (1);A_MULT_B1(3) <= A (3) and B (1);A_MULT_B2(0) <= A (0) and B (2);A_MULT_B2(1) <= A (1) and B (2);A_MULT_B2(2) <= A (2) and B (2);A_MULT_B2(3) <= A (3) and B (2);A_MULT_B3(0) <= A (0) and B (3);A_MULT_B3(1) <= A (1) and B (3);A_MULT_B3(2) <= A (2) and B (3);A_MULT_B3(3) <= A (3) and B (3);end if;end process;--------------------Second stage of the multiplier---------------add the all the partial products ,then get the result of the multiplier C_TEMP<=( "0000" & A_MULT_B0 )+( "000"& A_MULT_B1 &'0' )+( "00" & A_MULT_B2 & "00" )+( '0'&A_MULT_B3 & "000" );--build a signal register output---输出寄存,利于实现流水data_out <= C_TEMP; --output registerend multi_arch;九、实验总结。

基于VHDL语言的组合乘法器设计与仿真

基于VHDL语言的组合乘法器设计与仿真

i ii 《现代电子技术》20 05 年第 18 期总第 20 9 期þ 集 成 电 路 ü基于 VH DL 语言的组合乘法器设计与仿真刘姝延1 , 吴 志2 , 丁 红1 , 马秋明1( 1. 烟台师范学院 物理与电子工程学 院 山东 烟台 26 40 25; 2 . 烟台师范学院 基建处 山东 烟台 26 40 25 )摘 要: 基于 V H DL 的数字系统设计具有设计技术 齐全、方法灵活、支持广泛等优点, 同时也是 E DA 技术的重要 组成 部分。

文章用 V H DL 语言设计了左移法和进位节省法实现的两种组 合乘法器, 通过功能仿真 , 对两种乘法器的性能进 行了 比较, 从而得知后者的传输延迟时间小, 即速度较快 。

通过设 计实例, 介绍了利用 VH D L 语言进行数字系统设计的方法。

关键词: V H D L ; 组合乘法器; 左移法; 进位节省法中图分类号: T N 7 9 文 献标识码: B 文章编号: 1 00 4 37 3X ( 2 00 5) 18 0 77 0 2Design an d Simulation of Combin a tion a l Mu l t ip l ier Based on VH DL LanguageL I U Sh u y a n 1 , WU Zh i 2 , D I N G H o n g 1 , MA Q i u m i n g 1( 1 . Scho o l o f P hy s i cs a nd Elect ro nic E ng ineer ing , Ya nt ai Nor m a l Un iver si t y, Yant ai, 2 64 02 5, Ch ina;2 . Dep ar tmen t of Basic Bu ilding , Ya nt ai Nor m a l Un iver si t y, Yan t ai, 2 64 02 5, Ch ina)Abs t r a ct : Dig i t a l s y s t e ms u s i n g V H D L h a s t h e adv a n t a ges of comp r eh e n s i v e d e s i gn t e ch n o l o g i e s , fl e xi b l e des i g n met ho d s an d w i dera ng e s u p p o r t , it ′s al s o an i m po r t ant comp o n e n t o f E D A . T he co m b i n a t i o n a l mul t i p l i er s t o us e t w o met h o d s of left sh i f t s an d car rys a ve ar e des i g n e d i n V H D L la ng u a ge , by fun c t i o n a l s i mu l a t i o n , comp a r in g t h e pecu l i a ri t y o f t wo m ul t i p i er s , fi n d t h e car ry s a ve mu l t i - pl i er ′s del a y s h o r t e r , s p e ed fa st er. T h r o u g h d e si g n ex a mp l es , t h i s p a per in t r od u c es t h e met h o d of di g it al s y s t e ms des i g n based o nV H D L .Ke yw o rd s : VH D L ; comb i n a t i o n a l m ul t i p l i er ; met h o d o f left sh i ft ; met h o d o f carr y s a ve1 引 言随着计算机技术和大规模集成电路技术的发展, 传统 的通过 逻辑图 和布尔方 程设计 硬件电路 的方法 已大大落 后于当今 技术的发展, 取而代之 的是硬件描 述语言 H D L 使 用通用逻辑元、器件的限制, 电路尺寸大为缩小, 保密 程度大为提高。

(VHDL)8位二进制乘法器电路程序

(VHDL)8位二进制乘法器电路程序

8位二进制乘法电路该乘法器是有由8位加法器构成的以时序方式设计的8位乘法器,采用逐项移位相加的方法来实现相乘。

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

直到所有的部分积都被加过一次。

例如:被乘数(M7M6M5M4M3M2M1M0)和乘数(N7N6N5N4N3N2N1N0)分别为11010101和10010011,其计算过程如下:下面分解8位乘法器的层次结构,分为以下4个模块:①右移寄存器模块:这是一个8位右移寄存器,可将乘法运算中的被乘数加载于其中,同时进行乘法运算的移位操作。

②加法器模块:这是一个8位加法器,进行操作数的加法运算。

③1位乘法器模块:完成8位与1位的乘法运算。

④锁存器模块:这是一个16位锁存器,同时也是一个右移寄存器,在时钟信号的控制下完成输入数值的锁存与移位。

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

图中8位移位寄存器reg_8存放乘数a,从a的最低位开始,每次从reg_8中移出一位,送至1×8位乘法器multi_1中,同时将被乘数加至multi_1中,进行乘法运算,运算的结果再送至8位加法器adder_8中,同时取出16位移位寄存器reg_16的高8位与之进行相加,相加后结果即部分积存入reg_16中,进行移位后并保存。

这样经过8次对乘数a的移位操作,所以的部分积已全加至reg_16中,此时锁存器reg_16存放的值即所要求的积。

(1)8位移位寄存器reg_8的设计(A )电路框图(B8位移位寄存器是在时钟(r8_clk'event and r8_clk='1')信号作用下,当r8_load='1'时,将8位乘数加载进入;而当r8_load='0'时,对数据进行移位操作,同时定义一个信号reg8用来装载新数据及移位后的操作数,完成这些操作后,寄存器的最低位reg8(0)传送给r8_out 输出。

乘法器vhdl课程设计

乘法器vhdl课程设计

乘法器vhdl课程设计一、课程目标知识目标:1. 理解乘法器的原理及其在数字信号处理中的应用。

2. 掌握VHDL语言的基本语法和结构,能够使用VHDL进行简单的程序编写。

3. 学习并掌握利用VHDL设计乘法器的方法,理解其位运算和结构设计。

技能目标:1. 能够运用所学知识,独立设计并实现一个简单的乘法器VHDL程序。

2. 培养学生利用电子设计自动化(EDA)工具进行代码编写、仿真和测试的能力。

3. 提高学生的问题分析能力,学会使用VHDL解决实际的数字电路设计问题。

情感态度价值观目标:1. 培养学生对于电子信息和数字电路设计的兴趣,激发学生创新精神和探索欲望。

2. 增强团队合作意识,通过小组讨论和协作,提高学生之间的沟通能力和协作解决问题的能力。

3. 强化学生的工程伦理观念,了解所学技术在国家经济发展和国防建设中的重要性,树立正确的价值观。

本课程针对高年级电子信息工程及相关专业学生设计,结合学生已具备的基础知识和课程性质,以实践性和应用性为导向,旨在通过具体的乘法器VHDL课程设计,将理论知识与实践技能相结合,提升学生解决实际工程问题的能力。

通过本课程的学习,学生应能够展示出上述具体的学习成果。

二、教学内容1. 乘法器原理回顾:包括乘法器的基本工作原理,不同类型的乘法器结构对比,以及乘法器在数字信号处理中的应用。

- 相关教材章节:第三章“数字电路基础”,第5节“算术逻辑单元”。

2. VHDL语言基础:VHDL的基本语法,数据类型,信号与变量,运算符,顺序与并行语句,进程,实体和架构等。

- 相关教材章节:第五章“硬件描述语言VHDL”,第1-3节。

3. 乘法器的VHDL设计方法:- 位运算乘法器设计原理与实现。

- 流水线乘法器设计原理与实现。

- 相关教材章节:第五章“硬件描述语言VHDL”,第4节“VHDL设计实例”;第六章“数字信号处理器的硬件实现”,第2节“乘法器的硬件实现”。

4. EDA工具的应用:利用EDA工具进行VHDL代码的编写、编译、仿真和测试。

vhdl 四位流水线乘法器

vhdl 四位流水线乘法器

实验二四位流水线乘法器一、实验目的1.了解四位并行乘法器的原理。

2.了解四位并行乘法器的设计思想和流水线的实现方法。

3.掌握用VHDL 语言实现基本二进制运算的方法。

二、实验内容与要求通过开关和键盘输入两组4BIT的二进制数据,按照二进制加法器原理进行加和,求出和及进位,并通过LED显示灯输出显示,完成编译、综合、适配、仿真、实验箱上的硬件测试。

三、实验原理流水线结构的并行乘法器的最大有点就是速度快,尤其实在连续输入的乘法器中,可以达到近乎单周期的运算速度。

流水线乘法器是组合逻辑电路实现无符号数乘法的方法上发展而来的。

其关键是在组合逻辑电路的基础上插入寄存器。

假如有被乘数A 和乘数B,首先用A 与B 的最低位相乘得到S1,然后再把A 左移1 位与B 的第2 位相乘得到S2,再将A 左移3 位与B 的第三位相乘得到S3,依此类推,直到把B 的所有位都乘完为止,然后再把乘得的结果S1、S2、S3……相加即得到相乘的结果。

需要注意的是,具体实现乘法器是,并不是真正的去乘,而是利用简单的判断去实现,举个简单的例子。

假如A 左移n 位后与B 的第n 位相乘,如果B 的这位为‘1’,那么相乘的中间结果就是A 左移n 位后的结果,否则如果B 的这位为‘0’,那么就直接让相乘的中间结果为0 即可。

带B 的所有位相乘结束后,把所有的中间结果相加即得到A 与B 相乘的结果。

在此基础上插入寄存器即可实现流水线乘法器。

四、实验平台(1)硬件:计算机、GX-SOC/SOPC-DEV-LABCycloneII EP2C35F672C8核心板(2)软件:Quartus II软件PIN_AF8 DATAOUT[4] LED4PIN_AE7 DATAOUT[5] LED5PIN_AF7 DATAOUT[6] LED6PIN_AA11 DATAOUT[7] LED7PIN_AE21 BCD[0] 数码管DP4BPIN_AB20 BCD[1]PIN_AC20 BCD[2]PIN_AF20 BCD[3]PIN_AE20 BCD[4] 数码管DP5BPIN_AD19 BCD[5]PIN_AC19 BCD[6]PIN_AA17 BCD[7]PIN_AA18 BCD[8] 数码管DP6BPIN_W17 BCD[9]PIN_V17 BCD[10]PIN_AB18 BCD[11]六、仿真截图七、硬件实现八、程序代码1---clkgen.vhdlibrary IEEE;-- 1HZuse IEEE.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity clkgen isport (CLK : in std_logic;CLK1HZ: out std_logic);end entity;architecture clk_arch of clkgen issignal COUNT : integer range 0 to 50000000; --50MHZ -->1hz begin -- 50M/1=50000000 PROCESS(CLK)BEGINif clk'event and clk='1' thenIF COUNT= 50000000 thenCOUNT<=0;ELSE COUNT<=COUNT+1;END IF;END IF;END PROCESS;PROCESS(COUNT)BEGINIF COUNT= 5000000 THEN -- 1HZCLK1HZ<='1';ELSE CLK1HZ<='0';END IF;END PROCESS;end architecture;2—BCD-- 输出控制模块,把乘法器的输出转换成BCD码在数码管上显示、-- SCKZ.VHDlibrary IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity BIN2BCD isport ( DIN: in std_logic_vector(7 downto 0); ---The input 8bit binaryBCDOUT: out std_logic_vector(11 downto 0)--输出显示, 已转换成BCD码);end entity;architecture arch of BIN2BCD issignal data2,data3,data4 :std_logic_vector(9 downto 0);-- 输出数据缓存signal hundred,ten,unit:std_logic_vector(3 downto 0);--signal bcdbuffer:std_logic_vector(11 downto 0);---2'1111_1001_11=999beginBCDOUT<= bcdbuffer;bcdbuffer(11 downto 8)<=hundred;bcdbuffer(7 downto 4)<=ten;bcdbuffer(3 downto 0)<=unit;get_hundred_value:process(data2)beginDA TA2<="00"&DIN;---get hundred valueif data2>=900 thenhundred<="1001";--9data3<=data2-900;elsif data2>=800 thenhundred<="1000";--8data3<=data2-500;elsif data2>=700 thenhundred<="0111";--7data3<=data2-700;elsif data2>=600 thenhundred<="0110";--6data3<=data2-600;elsif data2>=500 thenhundred<="0101";--5data3<=data2-500;elsif data2>=400 thenhundred<="0100";--4data3<=data2-400;elsif data2>=300 thenhundred<="0011";--3data3<=data2-300;elsif data2>=200 thenhundred<="0010";--2data3<=data2-200;elsif data2>=100 thenhundred<="0001";--1data3<=data2-100;else data3<=data2;hundred<="0000";end if;end process; ---get_thousand_valueget_tens_value:process(data3) begin---get tens placeif data3>=90 thenten<="1001";--9data4<=data3-90;elsif data3>=80 thenten<="1000";--8data4<=data3-50;elsif data3>=70 thenten<="0111";--7data4<=data3-70;elsif data3>=60 thenten<="0110";--6data4<=data3-60;elsif data3>=50 thenten<="0101";--5data4<=data3-50;elsif data3>=40 thenten<="0100";--4data4<=data3-40;elsif data3>=30 thenten<="0011";--3data4<=data3-30;elsif data3>=20 thenten<="0010";--2data4<=data3-20;elsif data3>=10 thenten<="0001";--1data4<=data3-10;else data4<=data3;ten<="0000";end if;end process; ---get_ten_valueget_unit_value:process(data4)begin--unit's orderif (data4>0) thenunit<=data4(3 downto 0);else unit<="0000";end if;end process;end arch;3 multi4b --------------------------------------------------------------------------------/ -- DESCRIPTION : Signed mulitplier:-- AIN (A) input width : 4-- BIN (B) input width : 4-- Q (data_out) output width : 8-- 并行流水乘法器--------------------------------------------------------------------------------/--10 × 9 = 90-- 1 0 1 0-- 1 0 0 1 =-- --------------- 1 0 1 0-- 0 0 0 0 --partial products-- 0 0 0 0-- 1 0 1 0-- -------------------- 1 0 1 1 0 1 0--parallel : process all the inputs at the same time--pipeline : use several stages with registers to implement it----关键思想,插入寄存器library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity multi4b isport ( CLK: in STD_LOGIC; ---system clockAIN: in STD_LOGIC_VECTOR (3 downto 0); ---one inputBIN: in STD_LOGIC_VECTOR (3 downto 0);-- the other inputdata_out: out STD_LOGIC_VECTOR (7 downto 0)---the result ---make sure the biggest value ,i,e. 1111x1111=1110_0001 can be held in the register );end multi4b;architecture multi_arch of multi4b issignal A,B :std_logic_vector(3 downto 0); --input register---registers to hold the result of the first processing---registers added to make use of pipeline, the 1st stagesignal A_MULT_B0: STD_LOGIC_VECTOR (3 downto 0);signal A_MULT_B1: STD_LOGIC_VECTOR (3 downto 0);signal A_MULT_B2: STD_LOGIC_VECTOR (3 downto 0);signal A_MULT_B3: STD_LOGIC_VECTOR (3 downto 0);---register to hold the result of the multipliersignal C_TEMP : STD_LOGIC_VECTOR (7 downto 0);beginPROCESS(CLK,AIN,BIN)beginif CLK'EVENT AND CLK='1' THEN-- multiplier operand inputs are registeredA<= AIN;B<= BIN;-----------------Fist stage of the multiplier------------------here we get the axb(0),axb(1),axb(2),axb(3),i.e.partial products---put them into the responding registersA_MULT_B0(0) <= A (0) and B (0);----- multi 1 , get the a(0) and b(0), & put it into the register A_MULT_B0(0)A_MULT_B0(1) <= A (1) and B (0);A_MULT_B0(2) <= A (2) and B (0);A_MULT_B0(3) <= A (3) and B (0);--10 × 9 = 90-- 1 0 1 0-- 1 0 0 1 =-- --------------- 0 0 0 0 1 0 1 0-- 0 0 0 0 0 0 0 0 --partial products-- 0 0 0 0-- 1 0 1 0-- -------------------- 1 0 1 1 0 1 0A_MULT_B1(0) <= A (0) and B (1);A_MULT_B1(1) <= A (1) and B (1);A_MULT_B1(2) <= A (2) and B (1);A_MULT_B1(3) <= A (3) and B (1);A_MULT_B2(0) <= A (0) and B (2);A_MULT_B2(1) <= A (1) and B (2);A_MULT_B2(2) <= A (2) and B (2);A_MULT_B2(3) <= A (3) and B (2);A_MULT_B3(0) <= A (0) and B (3);A_MULT_B3(1) <= A (1) and B (3);A_MULT_B3(2) <= A (2) and B (3);A_MULT_B3(3) <= A (3) and B (3);end if;end process;--------------------Second stage of the multiplier---------------add the all the partial products ,then get the result of the multiplier C_TEMP<=( "0000" & A_MULT_B0 )+( "000"& A_MULT_B1 &'0' )+( "00" & A_MULT_B2 & "00" )+( '0'&A_MULT_B3 & "000" );--build a signal register output---输出寄存,利于实现流水data_out <= C_TEMP; --output registerend multi_arch;九、实验总结。

VHDL八位乘法器

VHDL八位乘法器

VHDL八位乘法器VHDL八位乘法器一.设计思路纯组合逻辑构成的乘法器虽然工作速度比较快,但过于占用硬件资源,难以实现宽位乘法器,基于PLD器件外接ROM九九表的乘法器则无法构成单片系统,也不实用。

这里介绍由八位加法器构成的以时序逻辑方式设计的八位乘法器,具有一定的实用价值,而且由FPGA构成实验系统后,可以很容易的用ASIC 大型集成芯片来完成,性价比高,可操作性强。

其乘法原理是:乘法通过逐项移位相加原理来实现,从被乘数的最低位开始,若为1,则乘数左移后与上一次的和相加;若为0,左移后以全零相加,直至被乘数的最高位。

二.方案设计与论证此设计是由八位加法器构成的以时序逻辑方式设计的八位乘法器,它的核心器件是八加法器,所以关键是设计好八位加法器。

方案:由两个四位加法器组合八位加法器,其中四位加法器是四位二进制并行加法器,它的原理简单,资源利用率和进位速度方面都比较好。

综合各方面的考虑,决定采用方案二。

三.工作原理ARICTL是乘法运算控制电路,它的START信号上的上跳沿与高电平有2个功能,即16位寄存器清零和被乘数A[7...0]]向移位寄存器SREG8B加载;它的低电平则作为乘法使能信号,乘法时钟信号从ARICTL的CLK输入。

当被乘数被加载于8位右移寄存器SREG8B后,随着每一时钟节拍,最低位在前,由低位至高位逐位移出。

当为1时,一位乘法器ANDARITH打开,8位乘数B[7..0]在同一节拍进入8位加法器,与上一次锁存在16位锁存器REG16B中的高8位进行相加,其和在下一时钟节拍的上升沿被锁进此锁存器。

而当被乘数的移出位为0时,一位乘法器全零输出。

如此往复,直至8个时钟脉冲后,由ARICTL 的控制,乘法运算过程自动中止,ARIEND输出高电平,乘法结束。

此时REG16B 的输出即为最后的乘积。

四.工作原理框图cin a[7..0]b[7..0]s[7..0]coutadder8binst1abin din[7..0]dout[7..0]andarithinst2clkstart clkout rstallariend arictl inst3clk clr d[8..0]q[15..0]reg16b inst5clk loaddin[7..0]qbsreg8b inst6dout[15..0]OUTPUTVCCB[7..0]INPUT VCCA[7..0]INPUT dout5[15..0]OUTPUT 五.程序清单1.library ieee; ----四位二进制并行加法器 use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all; entity add4b isport( cin:in std_logic;a,b:in std_logic_vector(3 downto 0); s:out std_logic_vector(3 downto 0); cout:out std_logic); end;architecture one of add4b issignal sint,aa,bb:std_logic_vector(4 downto 0); beginaa<='0' & a; bb<='0' & b; sint<=aa+bb+cin; s<=sint(3 downto 0); cout<=sint(4); end;2.library ieee; --由两个四位二进制并行加法器级联而成的八位二进制加法器;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all; entity adder8b isport( cin:in std_logic;a,b:in std_logic_vector(7 downto 0); s:out std_logic_vector(7 downto 0); cout:out std_logic); end;architecture one of adder8b iscomponent add4b --对要调用的元件add4b 的端口进行说明port( cin:in std_logic;a,b:in std_logic_vector(3 downto 0);s:out std_logic_vector(3 downto 0);cout:out std_logic);end component;signal carryout: std_logic;beginu1:add4b port map(cin,a(3 downto 0),b(3 downto 0),s(3 downto 0),carryout);u2:add4b port map(carryout,a(7 downto 4),b(7 downto 4),s(7 downto 4),cout);end;3.library ieee; --一位乘法器;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.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;architecture one of andarith isbeginprocess(abin,din)beginfor i in 0 to 7 loopdout(i)<=din(i) and abin;end loop;end process;end;4.library ieee; --乘法运算控制器use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity arictl isport( clk,start:in std_logic;clkout,rstall,ariend:out std_logic);end;architecture one of arictl issignal cnt4b:std_logic_vector(3 downto 0);beginrstall<=start;process(clk,start)beginif start='1' then cnt4b<="0000";elsif clk'event and clk='1' thenif cnt4b<8 then --小于8则计数,等于8则表明乘法运算已经结束cnt4b<=cnt4b+1;end if;end if;end process;process(clk,cnt4b,start)beginif start='0' thenif cnt4b<8 thenclkout<=clk; ariend<='0';else clkout<='0'; ariend<='1';end if;else clkout<=clk; ariend<='0';end if;end process;end;5.library ieee; --16位锁存器use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity reg16b isport( clk,clr:in std_logic;d:in std_logic_vector(8 downto 0);q:out std_logic_vector(15 downto 0));end;architecture one of reg16b issignal r16s:std_logic_vector(15 downto 0);beginprocess(clk,clr)beginif clr='1' then r16s<="0000000000000000";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;6.library ieee; --8位右移寄存器use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity sreg8b isport( clk,load:in std_logic;din:in std_logic_vector(7 downto 0);qb:out std_logic);end;architecture one of sreg8b issignal reg8:std_logic_vector(7 downto 0);beginprocess(clk,load)beginif clk'event and clk='1' thenif load='1' then reg8<=din;else reg8(6 downto 0)<=reg8(7 downto 1);end if;end if;end process;qb<=reg8(0);end;7.library ieee;--8位乘法器顶层设计use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity mult8x8 isport( clk:in std_logic;start:in std_logic;a,b:in std_logic_vector(7 downto 0);dout:out std_logic_vector(15 downto 0);ariend:out std_logic);end;architecture struc of mult8x8 iscomponent adder8b isport( cin:in std_logic;a,b:in std_logic_vector(7 downto 0);s:out std_logic_vector(7 downto 0);cout:out std_logic);end component;component andarith isport( abin:in std_logic;din:in std_logic_vector(7 downto 0);dout:out std_logic_vector(7 downto 0)); end component;component arictl isport( clk,start:in std_logic;clkout,rstall,ariend:out std_logic);end component;component reg16b isport( clk,clr:in std_logic;d:in std_logic_vector(8 downto 0);q:out std_logic_vector(15 downto 0));end component;component sreg8b isport( clk,load:in std_logic;din:in std_logic_vector(7 downto 0);qb:out std_logic);end component;signal gndint :std_logic;signal intclk :std_logic;signal rstall :std_logic;signal qb :std_logic;signal andsd :std_logic_vector(7 downto 0);signal dtbin :std_logic_vector(8 downto 0);signal dtbout :std_logic_vector(15 downto 0);begindout<=dtbout; gndint<='0';u1:arictl port map( clk,start,intclk,rstall,ariend);u2:sreg8b port map(intclk,rstall,b,qb);u3:andarith port map(qb,a,andsd);u4:adder8b port map(gndint,dtbout(15 downto 8),andsd,dtbin(7 downto 0),dtbin(8));u5:reg16b port map(intclk,rstall,dtbin,dtbout);end;六.仿真结果图。

利用VHDL设计乘法器

利用VHDL设计乘法器

在计算机结构里加,减,乘,除是常被用到的运算,本文提出以非常高速积体电路硬体描述语言(VHDL)来描述硬体,说明如何将两个运算元作相乘的运算。

我们首先以无号数整数做乘法运算来说明其原理,设计其电路结构。

其实在VHDL 程式中,我们更可以载入STD_LOGIC_ARITH与STD_LOGIC_UNSIGNED元件盒之后,直接进行乘法运算,既简单又容易扩充。

最后,我们将以4-bit X 4-bit的例子来做电路描述、电路合成、电路模拟并以七段显示器将其结果显示出来。

关键字:非常高速积体电路硬体描述语言、电路描述、电路合成、电路模拟Abstract We have known operation that perform addition, subtraction, multiplication, and division. In this paper we are presented primarily to describe hardware using by VHDL. We can explain how multiplication may be performed for two operand. Multiplication of unsigned numbers illustrates the main issues involved in the design of multiplier circuit. In fact, after the STD_LOGIC_ARITH and STD_LOGIC_UNSIGNED packages were added to the VHDL program, it became not only simple but also easy to extended. Next, consider a 4 x 4 example to circuit description, circuit synthesis, and circuit simulation by using VHDL. Finally, this approach can also be displayed by 7-segment.Keyword : VHDL , circuit description , circuit synthesis, circuit simulation利用VHDL 设计乘法器一.简介VHDL是V ery High Speed Integrated Circuit Hardware Description Language 的英文缩写。

10位乘法器的设计实验报告

10位乘法器的设计实验报告

10位乘法器的设计实验报告一、实验目的本实验旨在设计一个10位乘法器,通过实验掌握二进制数乘法的基本原理,熟悉硬件描述语言(如Verilog或VHDL)在数字电路设计中的应用,提高数字系统设计的能力。

二、实验原理二进制乘法的基本原理是按照二进制位进行相乘,然后进行累加。

具体来说,对于两个n位的二进制数A和B,它们的乘积可以表示为:A B = Σ(A[i] B[i] 2^(i)) (i从n-1到0)其中,A[i]和B[i]分别表示A和B的第i位,上标表示该位数的权重。

例如,对于8位二进制数,上标范围应为0到7。

为了实现二进制数的乘法,可以使用一位乘法器进行逐位相乘,并将结果累加得到最终的乘积。

因此,设计一个n位乘法器需要n个一位乘法器。

三、实验步骤1. 确定设计目标:本实验设计一个10位乘法器,输入为两个10位二进制数,输出为它们的乘积。

2. 编写Verilog代码:使用Verilog硬件描述语言编写一位乘法器的代码,然后使用同样的方式实现10位乘法器。

3. 仿真验证:使用仿真软件对设计的10位乘法器进行功能验证,确保其正确性。

4. 综合与布局布线:将Verilog代码综合成门级网表,并使用布局布线工具进行布局布线,生成可下载的硬件配置文件。

5. 下载测试:将硬件配置文件下载到FPGA开发板进行实际测试,验证设计的正确性和性能。

四、实验结果与分析通过实验,成功设计了一个10位乘法器,并进行了仿真验证和实际测试。

实验结果表明,设计的10位乘法器能够正确地实现二进制数的乘法运算,并且性能良好。

在仿真过程中,未发现任何语法错误、逻辑错误或时序错误。

在实际测试中,设计的10位乘法器能够快速准确地计算出两个10位二进制数的乘积,满足设计要求。

五、实验总结与建议本实验成功地设计了一个10位乘法器,掌握了二进制数乘法的基本原理和实现方法。

通过实验,熟悉了Verilog硬件描述语言在数字电路设计中的应用,提高了数字系统设计的能力。

VHDL实验:LPM使用及4×4乘法器的设计

VHDL实验:LPM使用及4×4乘法器的设计

VHDL实验四LPM使用及4×4乘法器的设计一.实验目的1.学习用帮助功能查看元件的说明。

2.学习在文本和图形编辑中调用LPM(参数化模块)。

3.深入学习用复杂可编程逻辑器件进行电子系统设计的方法。

二、实验仪器1.PC机一台。

2.KHF-1/KHF-2/KHF-3/KHF-4/KHF-5 CPLD/FPGA实验开发系统一套。

三.实验要求1.复习数字电路进行乘法器设计的方法。

2.预习实验内容。

3.用图形和文本两种方法进行设计。

四、实验内容和步骤1.图形方法设计电路(1)建立一个新项目,新建图形编辑文件。

(2)在Enter Symbol对话框Symbol Libraries 项中选向导;(3)完成向导后得出下图(4)加入输入输出引脚,电路如图3-7所示。

a[3..0] ~sw1 p103(最高位),sw2 p104,sw3 p111,sw4 p112b[3..0] ~sw5 p113(最高位),sw6 p114,sw7 p115,sw8 p116result[7..0]~由串行数码管显示,见实验2(5)编译并进行管脚分配(由用户自行指定)。

(6)后编译。

启动下载软件进行下载。

2.文本编辑输入(1)重新创建一个项目,新建文本输入文件.参考程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity yima isport(input:in std_logic_vector(7 downto 0);a:out std_logic_vector(6 downto 0);b:out std_logic_vector(6 downto 0));end yima;architecture arch_twelveto1 of yima isbeginwith input(7 downto 4) selectb<="0110000"when"0001", --1"1101101"when"0010", --2"1111001"when"0011", --3"0110011"when"0100", --4"1011011"when"0101", --5"1011111"when"0110", --6"1110000"when"0111", --7"1111111"when"1000", --8"1111011"when"1001", --9"1110111"when"1010", --A"0011111"when"1011", --B"1001110"when"1100", --C"0111101"when"1101", --D"1001111"when"1110", --E"1000111"when"1111", --F"1111110"when others; --0with input(3 downto 0) selecta<="0110000"when"0001", --1"1101101"when"0010", --2"1111001"when"0011", --3"0110011"when"0100", --4"1011011"when"0101", --5"1011111"when"0110", --6"1110000"when"0111", --7"1111111"when"1000", --8"1111011"when"1001", --9"1110111"when"1010", --A"0011111"when"1011", --B"1001110"when"1100", --C"0111101"when"1101", --D"1001111"when"1110", --E"1000111"when"1111", --F"1111110"when others; --0end arch_twelveto1;(2)编译,并进行管脚分配。

quartusII软件做4的位乘法器设计(vhdl语言)

quartusII软件做4的位乘法器设计(vhdl语言)

quartusII软件做4的位乘法器设计(vhdl语⾔)⽤quartus II 软件设计4位乘法器1. 并⾏乘法的算法:下⾯根据乘法例题来分析这种算法,题中M4,M3,M2,M1是被乘数,⽤M表⽰。

N4,N3,N2,N1是乘数,⽤N表⽰2.乘法模块Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity and4a isPort(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 isBeginProcess(en,a(3 downto 0))Beginr<=a;Elser<="0000";End if;End process;End behave;3.加法模块Library ieee;Use ieee.std_logic_1164.all;Entity ls283 isPort (o1,o2:in std_logic_vector(3 downto 0); res:out std_logic_vector(4 downto 0));Architecture behave of ls283 isBeginProcess(o1,o2)Beginres<=('0'&o1)+('0'&o2);End process;End behave;4.主程序Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity mul4p isPort (op1,op2:in std_logic_vector(3 downto 0);result:out std_logic_vector(7 downto 0));End mul4p;Architecture count of mul4p iscomponent 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;Beginsg<=('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;5.仿真波形图6.引脚分配图7.硬件下载编程与硬件实现在实现硬件测试时,选择8个按键作为4个数据的输⼊信号,⽤8个LED灯作为运算结果数据输出指⽰,每4个数作为⼀个⼆进制数值,通过LED灯的亮灭来显⽰乘法的运算结果。

用VHDL语言描述和实现乘法累加器设计

用VHDL语言描述和实现乘法累加器设计

设计应完成的功能要求:(1)乘法累加器的结构如下图所示,5位的被乘数X和5位的乘数Y输入后,暂存在寄存器5位的寄存器A和B中,寄存器A和B的输出首先相乘,得到10位乘积,该乘积通过选择信号sel的控制,可以和10位寄存器C的输出相加,相加结果保存在寄存器C中,实现乘法累加功能;也可以通过sel选择全零和乘积相加,实现乘法功能。

寄存器C的输出也是系统输出Z。

:用VHDL语言描述和实现乘法累加器设计(2)要求乘法器和加法器都采用电路描述,不采用算法描述。

(3)要求寄存器A,B,C具有异步清零功能,全部寄存器采用相同的时钟和清零信号。

(4)设计的最终输出是设计报告。

设计报告的内容要求:(1)设计报告的格式采用标准的深圳大学设计报告格式(2)设计报告应包括该电路的总体结构图和主要功能模块组成图;(3)设计报告应根据总体结构图,说明VHDL代码编写的设计思路和基本原理;(4)设计报告应完成该电路的VHDL代码设计;(5)设计报告应完成该电路的VHDL仿真分析。

一、实验目的用VHDL语言描述和实现乘法累加器设计二、实验内容和步骤一.总体结构图设计思路和原理:首先,寄存器A、B、C具有异步清零功能,rest在clk之前调用,当复位信号rest 为1时,寄存器A、B、C复位,当rest为0时,并且在它们同一时钟clk的上升沿到来时,输出将等于输入,起到了数据锁存功能。

同时,寄存器的输出Z既是整个结果的输出,也可以被内部引用,因此在定义Z的端口时,把端口类型定义为buffer。

5位的被乘数X和5位的乘数Y输入后,暂存在寄存器5位的寄存器A和B中,通过寄存器A、B的寄存,能够让不同时到达的数据X和Y能够在同一时钟的控制下同时参与运算,寄存器A和B的输出分别为x_temp和y_temp,他们首先相乘,得到10位乘积mul,该乘积通过选择信号sel的控制,当sel为1时,acc=z,即乘积mul可以和10位寄存器C的输出相加,相加结果保存在寄存器C中,实现乘法累加功能;当sel为0时,acc为全零,即选择全零和乘积相加,实现乘法功能。

VHDL加法器与乘法器

VHDL加法器与乘法器
多位加法器设计
串行进位加法器( 串行进位加法器(CRA) )
A0 B0 A1 B1 A2 B2 A3 B3
CI S
A
B CO
CI S
A
B CO
CI S
A
B CO
CI S
A
B CO
S0
S1
S2
S3
CO
设计方法:原理图、元件例化; 函数表达式
多位加法器设计
选择进位加法器( 选择进位加法器(CSLA) )
移位相加乘法器
BEGIN IF ST = '1' THEN -REGA := "00000000" & A; REGB := B; RESULT <= (OTHERS => '0'); SOUT <= '0'; REGRES := (OTHERS => '0'); CNT := (OTHERS => '0'); ELSIF CLK'EVENT AND CLK='1' THEN -IF REGB(0)='1' THEN -REGRES := REGRES + REGA; END IF; REGA(15 DOWNTO 1) := REGA(14 DOWNTO 0); -REGA(0):= '0'; -REGB(6 DOWNTO 0) := REGB(7 DOWNTO 1); -CNT := CNT + 1; -IF CNT="000" THEN -RESULT <= REGRES; -SOUT <= '1'; REGA := "00000000" & A; REGB := B;-REGRES := (OTHERS => '0'); -END IF; END IF; END PROCESS; END ARCHITECTURE; 初始化, 初始化,置位
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

数字电路课程设计题目乘法器设计班级实验二班学号姓名时间第十三、十四周地点科A-304指导陈学英唐青【摘要】:用FPGA设计完成基于半加器、全加器和保留进位思想设计的4BIT四级流水乘法器,用modelsim仿真其结果。

【目录】:第一章、实验任务及原理第二章、设计思路方法及方案第三章、FPGA模块程序设计与仿真第四章、结束语【正文】【第一章】:实验任务及原理本实验只要求编写乘法器的硬件代码,并用Modelsim进行仿真测试。

设计乘法器,两个输入都是4BIT,对所有输入相乘都得到正确结果,乘法器采用四级流水设计,以增加处理速度。

用modelsim仿真时,要求用时钟上升沿方式遍历所有输入,检查输出结果是否正确。

原理用到流水,进位保留思想。

【第二章】:设计思路及方案算法结构(无符号)由上图可见,乘法的运算最终是加法的运算,两个4BIT输入,输出为7BIT。

模块一、半加器:单比特输入相加,模块二、全加器:由两个半加器组成,有一个进位输入,模块三、进位保留加法器:最终程序结构图流水设计的原理:在前向割集上加入四级流水图一图二如上图所示方框代表触发器,五边形代表组合逻辑块,假设图一中逻辑块输入输出延时为Ta,图二将逻辑块切割成两块,延时分别为T1,T2,且Ta=T1+T2,并在两逻辑块之间加触发器,两个逻辑块工作频率都可以达到clk频率,故工作速度增加一倍,虽然时延增加了,但资源优化了许多。

【第三章】:FPGA程序模块及仿真半加器的程序模块:entity half_adder isport(a,b:in std_logic;s,cout:out std_logic);end half_adder;architecture Behavioral of half_adder isbegins<=a xor b;cout<=a and b;end Behavioral;全加器的程序模块:调用半加器,采用顶层设计entity full_adder isport(a,b,cin:in std_logic;s,cout:out std_logic);end full_adder;architecture Behavioral of full_adder iscomponent half_adderport(a,b:in std_logic;cout,s:out std_logic);end component;signal h1s,h1cout,h2cout:std_logic;beginu1:half_adder port map(a,b,h1cout,h1s);u2:half_adder port map(cin,h1s,h2cout,s);cout<=h1cout or h2cout;end Behavioral;乘法器的程序模块: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 mm isport(a:in std_logic_vector(3downto0);b:in std_logic_vector(3downto0);clk:in std_logic;reset:in std_logic;psum:out std_logic_vector(7downto0));end mm;architecture Behavioral of mm iscomponent half_adderport(a,b:in std_logic;s,cout:out std_logic);end component;component full_adderport(a,b,cin:in std_logic;s,cout:out std_logic);end component;signal x:std_logic_vector(1to16);-----原理图中从左到右------------原理图中,触发器从左到右,共四层,依次定义信号signal d1:std_logic_vector(1to16);signal d2:std_logic_vector(1to13);signal d3:std_logic_vector(1to10);signal d4:std_logic_vector(1to9);-----------原理图中,加法器从左到右,依次定义加法器输出的进位信号signal c1:std_logic_vector(1to3);signal c2:std_logic_vector(1to3);signal c3:std_logic_vector(1to3);signal c4:std_logic;signal c5:std_logic;----------原理图中,加法器从左到右,依次定义加法器输出的和信号signal s1:std_logic_vector(1to3);signal s2:std_logic_vector(1to3);signal s3:std_logic_vector(1to3);signal s4:std_logic_vector(1to2);signal s5:std_logic;--------第四层加法器间的信号signal e:std_logic;beginx(1)<=a(3)and b(3);x(2)<=a(3)and b(2);x(3)<=a(2)and b(3);x(4)<=a(3)and b(1);x(5)<=a(2)and b(2);x(6)<=a(1)and b(3);x(7)<=a(3)and b(0);x(8)<=a(2)and b(1);x(9)<=a(1)and b(2);x(10)<=a(0)and b(3);x(11)<=a(2)and b(0);x(12)<=a(1)and b(1);x(13)<=a(0)and b(2);x(14)<=a(1)and b(0);x(15)<=a(0)and b(1);x(16)<=a(0)and b(0);-------------------------------------all dff process(clk,reset)beginif reset='0'thend1<="0000000000000000";d2<="0000000000000";d3<="0000000000";d4<="000000000";elsif clk'event and clk='1'then --------------------------------------first d1(1)<=x(1);d1(2)<=x(2);d1(3)<=x(3);d1(4)<=x(4);d1(5)<=x(5);d1(6)<=x(6);d1(7)<=c1(1);d1(8)<=s1(1);d1(9)<=x(9);d1(10)<=x(10);d1(11)<=c1(2);d1(12)<=s1(2);d1(13)<=x(13);d1(14)<=c1(3);d1(15)<=s1(3);d1(16)<=x(16);--------------------------------------second d2(1)<=d1(1);d2(2)<=d1(2);d2(3)<=d1(3);d2(4)<=c2(1);d2(5)<=s2(1);d2(6)<=d1(6);d2(7)<=c2(2);d2(8)<=s2(2);d2(9)<=d1(10);d2(10)<=c2(3);d2(11)<=s2(3);d2(12)<=d1(15);d2(13)<=d1(16);--------------------------------------third d3(1)<=d2(1);d3(2)<=c3(1);d3(3)<=s3(1);d3(4)<=c3(2);d3(5)<=s3(2);d3(6)<=c3(3);d3(7)<=s3(3);d3(8)<=d2(11);d3(9)<=d2(12);d3(10)<=d2(13);-------------------------------------fourthd4(1)<=d3(1);d4(2)<=d3(2);d4(3)<=c4;d4(4)<=s4(1);d4(5)<=s4(2);d4(6)<=d3(7);d4(7)<=d3(8);d4(8)<=d3(9);d4(9)<=d3(10);end if;end process;----------共五层,每一层都是从左到右,依次调用映射。

------------------------------firstu1:half_adder port map(a=>x(7),b=>x(8),cout=>c1(1),s=>s1(1)); u2:half_adder port map(a=>x(11),b=>x(12),cout=>c1(2),s=>s1(2)); u3:half_adder port map(a=>x(14),b=>x(15),cout=>c1(3),s=>s1(3)); ------------------------------secondu4:full_adder port map(a=>d1(4),b=>d1(5),cin=>d1(7),cout=>c2(1),s=>s2(1));u5:full_adder port map(a=>d1(8),b=>d1(9),cin=>d1(11),cout=>c2(2),s=>s2(2));u6:full_adder port map(a=>d1(12),b=>d1(13),cin=>d1(14),cout=>c2(3),s=>s2(3));------------------------------thirdu7:full_adder port map(a=>d2(2),b=>d2(3),cin=>d2(4),cout=>c3(1),s=>s3(1));u8:full_adder port map(a=>d2(5),b=>d2(6),cin=>d2(7),cout=>c3(2),s=>s3(2));u9:full_adder port map(a=>d2(8),b=>d2(9),cin=>d2(10),cout=>c3(3),s=>s3(3));------------------------------fourthu10:half_adder port map(a=>d3(5),b=>d3(6),cout=>e,s=>s4(2));u11:full_adder port map(a=>d3(3),b=>d3(4),cin=>e,cout=>c4,s=>s4(1));------------------------------lastu12:full_adder port map(a=>d4(1),b=>d4(2),cin=>d4(3),cout=>c5,s=>s5);------------------------------overpsum(7)<=c5;psum(6)<=s5;psum(5)<=d4(4);psum(4)<=d4(5);psum(3)<=d4(6);psum(2)<=d4(7);psum(1)<=d4(8);psum(0)<=d4(9);end Behavioral;仿真模块:LIBRARY ieee;USE ieee.std_logic_1164.ALL;USE ieee.std_logic_unsigned.all;USE ieee.numeric_std.ALL;ENTITY testnew ISEND testnew;ARCHITECTURE behavior OF testnew IS--Component Declaration for the Unit Under Test(UUT) COMPONENT mmPORT(a:IN std_logic_vector(3downto0);b:IN std_logic_vector(3downto0);clk:IN std_logic;reset:IN std_logic;psum:OUT std_logic_vector(7downto0));END COMPONENT;--Inputssignal a:std_logic_vector(3downto0):=(others=>'0');signal b:std_logic_vector(3downto0):=(others=>'0');signal clk:std_logic:='0';signal reset:std_logic:='0';--Outputssignal psum:std_logic_vector(7downto0);--Clock period definitionssignal s0,s1,s2,s3:std_logic_vector(7downto0);signal test:std_logic;BEGIN--Instantiate the Unit Under Test(UUT)uut:mm PORT MAP(a=>a,b=>b,clk=>clk,reset=>reset,psum=>psum);--Clock process definitionsclk_process:processbeginclk<='0';wait for1us;clk<='1';wait for1us;end process;reset_process:processbeginreset<='0';wait for10ns;reset<='1';wait;end process;--时钟上升沿计数遍历所有可能输入值stim_proc:process(clk,reset)beginif reset='0'thena<="0000";b<="0000";elsif clk'event and clk='1'thenif a<"1111"then a<=a+'1';elsif a>"1110"thena<=(others=>'0');if b<"1111"then b<=b+'1';elsif b>"1110"thenb<=(others=>'0');end if;end if;-----------------------延迟四拍,使之与输出结果同步s0<=a*b;s1<=s0;s2<=s1;s3<=s2;---------信号test检验结果的正确与否,若正确,输出1,否则为0 if s3=psum then test<='1';else test<='0';end if;end if;end process;END;仿真结果:上图检测信号(test)一直是高电平;下图由开始部分看出,输出结果与输入延时了四拍;由此可见仿真结果是正确的。

相关文档
最新文档