版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年内训师(TTT)选拔、培养与认证实训报告
- 2026年口腔医学生五年学业与职业规划方案
- 2026二建《水利水电工程管理与实务》精讲课程讲义
- 磷酸项目单机试车方案
- 我靠协议书婚姻实现财务
- 工艺流程图教程模板
- 产品合作代理协议书
- 学生工作处工作制度模板
- 口才互动活动策划方案(3篇)
- 支护柱施工方案(3篇)
- T∕CECS 21-2024 超声法检测混凝土缺陷技术规程
- 4-07-03-02 国家职业标准劳动关系协调师 (2025年版)
- 预防青少年药物滥用-主题班会课件
- 第5单元 你是我的镜子(教学设计)-四年级心理健康上学期同步备课系列(浙教版)
- TPM-计划保全实践手册
- 劳动争议处理方案
- 江苏省扬州市扬州梅岭教育集团2024-2025学年八年级下学期3月月考语文试题(原卷版+解析版)
- 统编历史七年级下册(2024版)第8课-北宋的政治【课件】h
- 二零二五年度购车绿色出行积分协议书
- Unit15Itsamysterytome!(课件)新概念英语青少版2A
- 【MOOC】市场调查与研究-南京邮电大学 中国大学慕课MOOC答案
评论
0/150
提交评论