


版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 预防校园欺凌班会课件
- 顾客体验课件
- 心电图健康评估与应用
- 医院学会管理办法解读
- 音乐课件的作文
- 市政污水管网改造项目环境影响报告书(模板)
- 城镇污水管网建设项目投资估算方案(参考模板)
- xx河流排水防涝设施建设项目节能评估报告(参考)
- 2025年商务、清洗服务项目建议书
- 2025年差压变送器合作协议书
- GB/T 18380.33-2022电缆和光缆在火焰条件下的燃烧试验第33部分:垂直安装的成束电线电缆火焰垂直蔓延试验A类
- 第一章-护理学基础绪论
- 烟花爆竹经营单位安全管理人员培训教材课件
- J波与J波综合征课件
- 微整面部美学设计面部风水设计课件
- 5吨龙门吊安装与拆除专项施工方案
- 康复科护理质量监测指标
- 农药基本常识课件
- 六年级数学分数除法、解方程计算题 (含答案)
- 高速铁路竣工验收办法
- 拟投入公路工程施工设备检测仪器设备表
评论
0/150
提交评论