北理工VHDL实验报告(3)

2020-05-05 13:31

实验三 十六位加法器设计

一、实验目的

(1)掌握元件例化的方法

(2)理解for/generate语句的用法

(3)编程完成4位加法器和16位加法器的设计

二、实验原理

(1)元件的例化

元件声明是对VHDL模块(即底层设计,也是完整的VHDL设计)的说明,使之可在其他被调用,元件声明可放在程序包中,也可在某个设计的构造体中声明。 元件例化指元件的调用。元件声明及元件例化的语法分别如下:

元件声明:

component〈元件实体名〉 prot(〈元件端口信息,同该元件实现时的实体的port部分〉); end compnent; 元件例化: 〈例化名〉:〈实体名,即元件名〉port map(〈端口列表〉);

(2)生成语句(GENERATE)

GENERATE语句用于循环执行某项操作。

FOR模式的生成语句主要用于相同结构的描述中; FOR模式语法结构: FOR/GENERATE:

标号:FOR 变量IN 离散区间GENERATE (并行处理语句); END GENERATE;

(3)16位加法器的设计

三、实验代码

4位加法器: library ieee;

use ieee.std_logic_1164.all;

entity adder4 is

port(a,b:in std_logic_vector(3 downto 0); cin:in std_logic;

s:out std_logic_vector(3 downto 0); cout:out std_logic); end adder4;

architecture behav of adder4 is

signal c: std_logic_vector(4 downto 0); signal p: std_logic_vector(3 downto 0); signal g: std_logic_vector(3 downto 0); begin

G1:for i in 0 to 3 generate p(i)<=a(i) xor b(i); g(i)<=a(i) and b(i); s(i)<=p(i) xor c(i); end generate; c(0)<=cin;

c(1)<=(cin and p(0)) or g(0);

c(2)<=(cin and p(0) and P(1)) or (g(0) and p(1)) or g(1);

c(3)<=(cin and p(0) and P(1)and P(2)) or (g(0) and p(1) and P(2)) or (g(1) and P(2)) or g(2);

c(4)<=(cin and p(0) and P(1)and P(2) and P(3)) or (g(0) and p(1) and P(2) and P(3)) or (g(1) and P(2) and P(3)) or (g(2) and P(3)) or g(3); cout<=c(4); end behav;

16位加法器: library ieee;

use ieee.std_logic_1164.all;

entity adder is

port(a,b:in std_logic_vector(15 downto 0); s:out std_logic_vector(15 downto 0);

cin:in std_logic; cout:out std_logic); end adder;

architecture behav of adder is component adder4 is

port(a,b:in std_logic_vector(3 downto 0); s:out std_logic_vector(3 downto 0); cin:in std_logic; cout:out std_logic); end component;

signal m1,m2,m3:std_logic; begin

u1:adder4 port map(a(3 downto 0),b(3 downto 0),s(3 downto 0),cin,m1); u2:adder4 port map(a(7 downto 4),b(7 downto 4),s(7 downto 4),m1,m2); u3:adder4 port map(a(11 downto 8),b(11 downto 8),s(11 downto 8),m2,m3);

u4:adder4 port map(a(15 downto 12),b(15 downto 12),s(15 downto 12),m3,cout); end behav;

测试程序: library ieee;

use ieee.std_logic_1164.all; entity adder_tb is end entity adder_tb;

architecture behav of adder_tb is component adder

port(a,b:in std_logic_vector(15 downto 0); s:out std_logic_vector(15 downto 0); cin:in std_logic; cout:out std_logic); end component;

signal clk:std_logic:='0';

signal a,b:std_logic_vector(15 downto 0); signal s:std_logic_vector(15 downto 0); signal cin:std_logic; signal cout: std_logic;

begin

w: adder port map(

a=>a,b=>b,s=>s,cin=>cin,cout=>cout ); process begin

a<=x\ b<=x\ cin<='1';

wait for 100ns;

a<=\ b<=\ cin<='0';

wait for 100ns;

a<=x\ b<=x\ cin<='1';

wait for 100ns;

a<=\ b<=\ cin<='1'; wait ;

end process; end behav;

四、仿真结果

实验四 选择运算器

一、实验目的:

(1)对前几次实验用到的知识进行总结

(2)综合运用理论课上的知识,完成选择运算器的设计

二、实验原理

(1)设计要求:

输出信号:一个COUT(15:0) ,16位 乘法器:要求用部分积实现

加法器:8位加法器,高7位补零

完成比较器、乘法器、加法器的设计,不可以直接使用+,x运算符直接实现。

(2)选择器运算器总原理图如下:

(3)乘法器部分采用并行乘法器


北理工VHDL实验报告(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:学习消防心得体会

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: