77范文网 - 专业文章范例文档资料分享平台

16位全加器(3)

来源:网络收集 时间:2018-11-17 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

图3.4 十六位全加器组成原理图

16位全加器总共有16位输入,而每四位为一组输入到4位先行进位加法器中进行加法运算,一般输入是两位二进制数,如图是:Y4-1 X4-1 一直到Y16-13 X16-13 为输入;输出为F,共16位输出,而和输出一样四位为一组一起经过运算后输出,不同的是输入有两个二进制数,而输出只有一个二进制数;C表示进位,C0初始值为1,后面的C4,C8,C12,C16分别是每个四位加法器运算后的进位。

2. 软件方案

用VHDL编写代码验证:

在对真值表进行分析和各个功能设计完成之后,就可以使用VHDL编写程序,运用MAX-PLUSⅡ进行模拟仿真,以验证其正确性。如下就是四位先行进位全加器和16位全加器的VHDL代码。

//导入各种所需要的库 library IEEE;

- 11 -

use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL;

-- Uncomment the following lines to use the declarations that are -- provided for instantiating Xilinx primitive components. --library UNISIM;

--use UNISIM.VComponents.all;

entity test is port(

a,b:in std_logic_vector(3 downto 0); //a,b为输入,为4位标准逻辑矢量类型

cin:in std_logic; //cin为输入,为标准矢量类型 s:out std_logic_vector(3 downto 0); //s为输出,为4位标准逻辑矢量类型

cout:out std_logic); //cout为输出,为标准矢量类型 end test;

architecture Behavioral of test is

signal d,t:std_logic_vector(3 downto 0); //信号量d,t为4位标准逻辑矢量

signal c:std_logic_vector(4 downto 0); //信号量c为5位标准逻辑矢量

- 12 -

begin

as_add: for i in 0 to 3 generate //i从0循环到3,循环4次

d(i)<=a(i) and b(i); //把a,b相与的结果赋给d t(i)<=a(i) or b(i); //把a,b相或的结果赋给t s(i)<=a(i) xor b(i) xor c(i); //把a,b,c进行异或的结果赋给s end generate; //以下为赋值语句 c(0)<=cin;

c(1)<=d(0) or (t(0) and c(0));

c(2)<=d(1) or (t(1) and d(0)) or (t(1) and t(0) and c(0));

c(3)<=d(2) or (t(2) and d(1)) or (t(1) and t(2) and d(0)) or (t(1) and t(2) and t(0) and c(0)) ;

c(4)<=d(3) or (t(3) and d(2)) or (t(3) and t(2) and d(1)) or (t(1) and t(2) and t(3) and d(0)) or (t(3) and t(2) and t(1) and t(0) and c(0)); cout<=c(4);

end Behavioral;

如下是16位全加器的VHDL代码。 library IEEE;

use IEEE.std_logic_1164.all; //导入各种需要的库

entity adder16 is

- 13 -

generic(n : integer := 16);

port (a : in std_logic_vector(16 downto 1); //a为16位标准逻辑矢量类型的输入

b : in std_logic_vector(16 downto 1); //b为16位标准逻辑矢量类型的输入

cin : in std_logic; //c为标准逻辑类型的输入 sum : out std_logic_vector(16 downto 1); //sum为16位标准逻辑矢量类型的输入 cout : out std_logic); end adder16;

-- structural implementation of the 16-bit adder architecture structural of adder16 is

component adder

//以下a,b,cin,sum,cout都为标准逻辑类型,其中a,b,cin为输入,sum,cout为输出

port (a : in std_logic; b : in std_logic; cin : in std_logic; sum : out std_logic; cout : out std_logic); end component;

signal carry : std_logic_vector(0 to 16); begin

- 14 -

carry(0) <= cin; //把信号量cin 的值赋给carry(0) cout <= carry(16); //把信号量carry(16)的值赋给cout

-- instantiate a single-bit adder 16 times

gen: for I in 1 to 16 generate //I从1循环至16,循环16次

add: adder port map(

//以下为赋值语句

a => a(I), b => b(I), cin => carry(I - 1), sum => sum(I), cout => carry(I));

end generate; end structural;

-- behavioral implementation of the 16-bit adder

architecture behavioral of adder16 is //定义结构体 begin

p1: process(a, b, cin) //过程开始

variable vsum : std_logic_vector(16 downto 1); variable carry : std_logic;

begin

- 15 -

carry := cin;

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库16位全加器(3)在线全文阅读。

16位全加器(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/279860.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: