基于VHDL语言的8位加法器的设计_第1页
基于VHDL语言的8位加法器的设计_第2页
基于VHDL语言的8位加法器的设计_第3页
基于VHDL语言的8位加法器的设计_第4页
基于VHDL语言的8位加法器的设计_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、基于 vhdl 语言的8位加法器的设计 摘要 利用vhdl言语,实现两个4位并行进位加法器,然后将其级联成为一个8位加法器,再实现一个二进制转换成十进制动态显模块,以显示相加结果,并在仿真软max+plus ii中进行仿真。关键词 vhdl、加法器、max+plus iidesign of 8-bit adder based on vhdl abstract: using vhdl, and the road to achieve two 4-bit adder, and then cascade into an 8-bit adder, and then converted to decim

2、al binary to achieve a dynamic explicit module to display the sum of the results, and the simulation software max + plus ii for simulation.key words vhdl, adder, max + plus ii0. 引言加法器是用来实现加法的器件,即它是产生数的和的装置。加数和被加数为输入,和数与进位为输出的装置为半加器。若加数、被加数与低位的进位数为输入,而和数与进位为输出则为全加器。加法器常用作计算机算术逻辑部件,执行逻辑操作、移位与指令调用,是计算机

3、进行算术逻辑运算的基本部件。研究加法器的实现对于电子硬件设计及其的理论发展的认识和理解具有重要意义。1. 设计原理加法器是数字系统中的基本逻辑器件。为了节省系统资源,减法器和硬件乘法器一般都由加法器来构成。但宽位加法器的设计是很耗费资源的,因此在实际的设计和相关系统的开发中需要注意资源的利用率和进位速度两方面的问题。多位加法器的构成有两种方式:并行进位和串行进位方式。并行进位加法器设有并行进位产生逻辑,运算速度快;串行进位方式是将全加器级联构成多位加法器。通常,并行加法器比串行级联加法器的资源占用更多的资源,并且随着位数的增加,相同位数的并行加法器比串行加法器的资源占用差距也会越来越大。实验及

4、事实证明,4位二进制并行加法器和串行级联加法器占用几乎相同的资源。这样,多位数加法器由4位二进制并行加法器级联构成是较好的折中选择。因此,8位加法器采用两个4位二进制并行加法器级联而成。1.1. 实现框图1.1.1. 四位加法器的实现框图如图1.1.1所示,四位加法器采用四个一位全加器级连成串行进位加法器。图1.1四位串行进位加法器其中csa为一位全加器,a和b为加法器的输入位串,对于四位加法器则位宽为4位,d为加法器输出位串,位宽和输入位串相同,c为进位输入(ci)或输出(co)。1.1.2. 减小运算的延迟显然,对于图1.1.1 这种方式,因高位运算必须要等低位进位来到后才能进行,因此它的

5、延迟相当大,运算效率低。由于运算的延迟主要是由进位延迟引起的,所以减少进位的延迟对提高运算速度非常有效。采用图1.1.2所示方法,将进位中的迭代关系去掉,则各位彼此独立,进位传播不复存在。因此,总的延迟是两级门的延迟。这样便可大大减小运算的延迟,从而提高运算效率,实现高速运算。图1.2四位加法器的超前进位的实现图1.2 为四位加法器的超前进位的实现原理图,其中,g表示进位生成位串,与输入位宽相同,p表示进位传输位串,与输入位宽相同。其意义为:如g为1,则必定产生进位,若p为1,则向高位传输进位。当进行加法运算时,g = a and b,p = a or b;当进行减法运算时,g = a and

6、 (not b),p = a or (not b)。根据图1.2可得到四位加法器的各级进位输出为:c0 = g0 or p0 and cic1 = g1 or p1 and co = g1 or p1 and g0 or p1 and p0 and cic2 = g2 or p2 and c1 = g2 or p2 and g1 or p2 and p1 and g0 or p2 and p1 and p0 and cic3 = g3 or p3 and c2 = g3 or p3 and g2 or p2 and g1 or p2 and p1 and g0 or p2 and p1 and

7、 p0 and cico = c3d = a and b and c = (a and ) xor (a or b) xor c = g xor p xor c上式中 and 为与操作,or 为或操作,not 为非操作,xor 异或操作。1.1.3. 八加法器的实现框图8位加法器采用两个4位二进制并行加法器级联而成。四位加法器采用四个一位全加器级连成串行进位加法器,实现框图如图1.3所示。图1.3 用两个并行四位加法器实现一个八位加法器2. 计设过程要实现8位加法器,需要三个子程序:1.四位加法器;2.二进制转十进制显示模块;3.动态显示模块。2.1. 设计思路利用vhdl言语,实现两个4并行

8、进位加法器,然后将其级联成为一个8位加法器,再实现一个十进制动态显模块,以显示加数、被加数以及相加结果,并在max + plus ii 中进行仿真。十进制动态显示模块可以通过设计一个9位二进制转换成十进制的显示子程序,并采用分频来实现。2.1.1. 四位二进制并行加法器的设计运用四个全加器级连成串行进位加法器。程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity add4 is port(a,b:in std_logic_vector(3 downto 0); ci:in std

9、_logic; co:out std_logic; so:out std_logic_vector(3 downto 0);end entity add4;architecture h1 of add4 isbegin process(a,b) is variable cq,qq,sq:std_logic_vector(3 downto 0); begin qq(0):=not(a(0)xor(not(b(0);sq(0):=not(qq(0) xor (not(ci); if (a(0) xor b(0)=1) then cq(0):=ci; -低位相加并产生进位。 else cq(0):=

10、a(0); end if; qq(1):= not(a(1) xor (not(b(1);sq(1):=not(qq(1) xor (not(cq(0); -第二位于前一进位相加,并产生进位。 if(a(1) xor b(1)=1) then cq(1):=cq(0); else cq(1):=a(1); end if; qq(2):= not(a(2) xor (not(b(2);sq(2):= not(qq(2) xor (not(cq(1); if (a(2) xor b(2)=1) then cq(2):= cq(1); else cq(2):=a(2); end if; qq(3):

11、= not(a(3) xor (not b(3);sq(3):= not(qq(3) xor (not(cq(2);-前一位进位与高位相加并产生进位。 if (a(3) xor b(3)=1) then cq(3):= cq(2); else cq(3):=a(3); end if; co=cq(3);so=sq; end process;end architecture h1;2.2.2 四位并行加法器波形四位加法器的波形如形如图2.1所示,由图可知仿真结果与理论实际相符。2.1 四位并行加法器波形图3. 转换显示模块的设计3.1. 二进制转换成十进制并显示加法器得到的和为二进制,设计以下二

12、进制到十进制转换显示程序使它显示为十进制。程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity look isport(d:in std_logic_vector(8 downto 0); clk3:in std_logic; smg:out std_logic_vector(2 downto 0); led7s: out std_logic_vector(6 downto 0);end entity look;archi

13、tecture one of look issignal ai,bi,ci: integer range 0 to 9;signal xi: std_logic_vector(2 downto 0);signal led7s1: std_logic_vector(20 downto 0);signal di: integer range 0 to 512;begin di=conv_integer(d); process(di) is variable a,b,c: integer range 0 to 9; begin a:=di rem 10; -把整型数的个位赋值给a b:=(di-a)

14、 rem 100)/10; -把整型数的十位赋值给b c:=(di-a-10*b)/100; -把整型数的百位赋值给c ai=a;bi=b;ciled7s1(6 downto 0)led7s1(6 downto 0)led7s1(6 downto 0)led7s1(6 downto 0)led7s1(6 downto 0)led7s1(6 downto 0)led7s1(6 downto 0)led7s1(6 downto 0)led7s1(6 downto 0)led7s1(6 downto 0)led7s1(6 downto 0)led7s1(13 downto 7)led7s1(13 d

15、ownto 7)led7s1(13 downto 7)led7s1(13 downto 7)led7s1(13 downto 7)led7s1(13 downto 7)led7s1(13 downto 7)led7s1(13 downto 7)led7s1(13 downto 7)led7s1(13 downto 7)led7s1(13 downto 7)led7s1(20 downto 14)led7s1(20 downto 14)led7s1(20 downto 14)led7s1(20 downto 14)led7s1(20 downto 14)led7s1(20 downto 14)l

16、ed7s1(20 downto 14)led7s1(20 downto 14)led7s1(20 downto 14)led7s1(20 downto 14)led7s1(20 downto 14)=xxxxxxx; end case; end process; process(clk3) variable x: std_logic_vector(2 downto 0); -定义一个常量,用来控制位选。 begin if clk3event and clk3=1 then if x0); end if; end if; xiled7s1=led7s1(6 downto 0);smgled7s1

17、=led7s1(13 downto 7);smgled7s1=led7s1(20 downto 14);smgled7s1=xxxxxxx;smg=xxx; end case; end process;end architecture one;3.2. 二进制转十进制显示模块波形输入8位二进制及进位位时,输出个位、十位、百位波形如图3.1所示,由图可知仿真结果与理论实际相符。3.1 二进制转十进制显示模块波形图4. 动态显示模块的设计4.1. 动态显示的模块的实现其程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_

18、unsigned.all;entity counter is port(e1,e2,clk3:in std_logic; q1: out std_logic_vector(2 downto 0);end entity counter;architecture bhv of counter isbegin process(clk3,e1,e2) is variable cout: integer:=0; begin if clk3event and clk3=1 then cout:=cout+1; end if; if e1=1 then q1=001; cout:=0;-输入加数,数码管显示加数。 end if; if e2=1 then q11050 then q1ai(3 downto 0),b=bi(3 downto 0),ci=e, co=e,so=sum(3 downto 0); u2:add4 port map(a=ai(7 downto 4),

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论