


版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、第 5 章习题参考答案problem 5.1 library ieee;use ieee.std_logic_1164.all;package my_data_type is constant m: integer :=8;type vector_array is array (natural range<>) of std_logic_vector(m-1 downto 0);end my_data_type;library ieee;use ieee.std_logic_1164.all; use work.my_data_type.all; entity n_mux isge
2、neric (n: integer :=8);port( datain: in vector_array(0 to n-1) ; sel: in integer range 0 to n-1;dataout: out std_logic_vector( m-1 downto 0);end;architecture bhv of n_mux is begindataout<=datain(sel); end;problem 5.2方法一:利用简单赋值语句设计library ieee;use ieee.std_logic_1164.all; entity priority_encoder i
3、sport(x:in std_logic_vector(7 downto 1);y:out std_logic_vector(2 downto 0);end;architecture bhv of priority_encoder is beginy(2)<=x(7) or x(6) or x(5) or x(4);y(1)<=x(7) or x(6) or ( not x(5) and not x(4) and (x(3) or x(2);y(0)<=x(7) or (not x(6) and(x(5) or (not x(4) and (x(3) or (not x(2)
4、 and x(1);end;方法二:利用 when 语句设计library ieee;use ieee.std_logic_1164.all; entity priority_encoder isport(x:in std_logic_vector(7 downto 1);y:out std_logic_vector(2 downto 0);end;architecture bhv of priority_encoder is beginy<="111" when x(7)='1' else"110" when x(6)='
5、1' else "101" when x(5)='1' else "100" when x(4)='1' else "011" when x(3)='1' else "010" when x(2)='1' else "001" when x(1)='1' else "000"end; problem 5.4 library ieee;use ieee.std_logic_1164.all;
6、 use ieee.std_logic_unsigned.all; entity adder8 isport(a,b:in std_logic_vector(7 downto 0); cin:in std_logic;sum:out std_logic_vector(7 downto 0); cout:out std_logic);end;architecture bhv of adder8 issignal a0,b0,cin0, s:std_logic_vector(8 downto 0); begina0<='0'&a; b0<='0'
7、&b; cin0<="00000000"&cin;s<=a0+b0+cin0; sum<=s(7 downto 0); cout<=s(8);end; problem5.5 library ieee;use ieee.std_logic_1164.all; use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all; use ieee.std_logic_signed.all; entity add_sub isport(a,b:in unsigned(7 downto 0
8、);sel:in bit_vector(1 downto 0);sum:out std_logic_vector(8 downto 0);end;architecture bhv of add_sub issignal temp1,temp2:unsigned (8 downto 0); signal temp3,temp4:signed(8 downto 0);-signal an,as,sn,ss:std_logic_vector(8 downto 0);signal a0,b0:signed (7 downto 0);signal cin0:std_logic_vector(7 down
9、to 0); begina0<=conv_signed(a,8);b0<=conv_signed(b,8); temp1<=conv_unsigned(a+b),9); temp2<=conv_unsigned(a-b),9); temp3<=conv_signed(a0+b0),9); temp4<=conv_signed(a0-b0),9);sum<=conv_std_logic_vector(temp1,9)when sel="00" else conv_std_logic_vector(temp3,9)when sel=&q
10、uot;01" else conv_std_logic_vector(temp2,9)when sel="10" else conv_std_logic_vector(temp4,9);end; problem 5.6 library ieee;use ieee.std_logic_1164.all; entity gray_encoder is generic(n: integer:=4) ;port(input:in std_logic_vector(n-1 downto 0);output:out std_logic_vector(n-1 downto 0)
11、;end;architecture bhv of gray_encoder is beginoutput(n-1)<=input(n-1);output(n-2 downto 0)<=input(n-2 downto 0) xor input(n-1 downto 1); end;problem 5.(7 将原题修改后的作业题, 要求能够实现连续移位, 当 shift信号为 0 时,保持不变,否则每次左移移位,最低位补0,直到全 0为止。)library ieee;use ieee.std_logic_1164.all; entity barrel_shifter isport(i
12、np:in std_logic_vector(7 downto 0); shift: in bit;sel:in integer range 0 to 7;outp:out std_logic_vector(7 downto 0);end;architecture bhv of barrel_shifter istype matrix is array(7 downto 0) of std_logic_vector (7 downto 0); signal row: matrix;beginrow(0)<=inp;l1:for i in 1 to 7 generaterow(i)<
13、=row(0) when shift='0' else row(i-1)(6 downto 0)&'0' ;end generate;outp<=row(sel); end;problem 5.8library ieee;use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; entity comp isport(a,b:in integer range 0 to 255; sel:in std_logic; x1,x2,x3:out std_logic);end;architectur
14、e bhv of comp issignal a_signed, b_signed: signed(7 downto 0); signal temp: std_logic_vector (1 to 4);begina_signed<=conv_signed(a,8); b_signed<=conv_signed(b,8); temp(1)<='1' when a>b else'0'temp(2)<='1' when a=b else'0'temp(3)<='1' when a_signed>b_signed else '0'temp(4)<='1
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年度不锈钢扶手专利授权许可合同
- 2025届湖南省长沙市地质中学高三一模语文试题及答案
- 二零二五年度特色门面出租合同终止与品牌合作引入协议
- 二零二五年度展会现场展台搭建与物料租赁合同
- 2025年度电子商务平台会员权益保护与合同法实施合同
- 2025年度汽车车位租赁与停车场租赁权租赁权买卖合同
- 古代文学作品分析方法试题及答案
- 数学建模培训案例
- 颅内脑动脉瘤的护理
- 建材样本审核协议
- 铁路钢轨探伤合同(2篇)
- 广州市海珠区六中鹭翔杯物理体验卷
- 国家职业技术技能标准 6-28-01-14 变配电运行值班员 人社厅发2019101号
- 肿瘤患者的康复与护理
- 电机学完整全套教学课件2
- 新版《铁道概论》考试复习试题库(含答案)
- 中国柠檬行业分析报告:进出口贸易、行业现状、前景研究(智研咨询发布)
- 【课件】人居与环境-诗意的栖居+课件高中美术人美版(2019)+必修+美术鉴赏
- 全国大学英语四级考试考试大纲(2023修订版)
- 抖音本地生活商家直播培训
- 鸢飞鱼跃:〈四书〉经典导读智慧树知到答案2024年四川大学
评论
0/150
提交评论