EDA技术与Verilog设计第六章课后习题部分答案.ppt

上传人:max****ui 文档编号:6340644 上传时间:2020-02-23 格式:PPT 页数:31 大小:1.53MB
返回 下载 相关 举报
EDA技术与Verilog设计第六章课后习题部分答案.ppt_第1页
第1页 / 共31页
EDA技术与Verilog设计第六章课后习题部分答案.ppt_第2页
第2页 / 共31页
EDA技术与Verilog设计第六章课后习题部分答案.ppt_第3页
第3页 / 共31页
点击查看更多>>
资源描述
6 11 6 11试编写求补码的Verilog程序 输入是带符号的8位二进制数modulewytest data in data out 习题6 11input 7 0 data in output 7 0 data out reg 7 0 data out always data in beginif data in 7 正数负数判断 从最高是否为1来判断data out data in 1 8 h80 elsedata out data in endendmodule 6 11仿真波形 8A 原码表示的十进制数 100A 十进制数10B6 原码表示的十进制数 5436 十进制数5380 原码表示的十进制数128 6 12 6 12编写两个四位二进制数相减的verilog程序modulewytest opr1 opr2 out data 完成Opr1 opr2的运算input 3 0 opr1 opr2 output 4 0 out data reg 3 0 out regcout function 3 0 abs input 3 0 data case data 3 1 b0 abs data 1 b1 abs data 1 对负数求绝对值 按位取反再加1endcaseendfunction 6 12 always opr1oropr2 case opr1 3 opr2 3 2 b00 cout out opr1 opr2 两个正数相减2 b01 cout out opr1 abs opr2 正数减负数 化为加法运算2 b10 cout out abs opr1 opr2 负数减正数 化为加法再取反2 b11 cout out abs opr2 abs opr1 负数相减 化为绝对值相减 顺序调换 endcaseassignout data cout out endmodule 6 12 6 12仿真波形 6 13 6 13有一个比较电路 当输入的一位BCD码大于4时 输出1 否则输出0 modulewytest bcd in out input 3 0 bcd in outputout assignout bcd in 4 1 0 endmodule 6 13 仿真波形 6 13 modulewytest bcd in out 习题6 13input 3 0 bcd in outputout assignout bcd in 4 1 0 regout always bcd in if bcd in 4 0 out 1 elseout 0 endmodule 6 13 6 14 试编写一个实现3输入与非门的verilog程序 modulewytest a o input 2 0 a outputo nandnand3 o a 0 a 1 a 2 endmodule 6 14 6 15 6 15设计74138译码器电路 6 15 modulewytest s1 s2 in out inputs1 input 1 0 s2 input 2 0 in output 7 0 out reg 8 0 out always s1ors2orin beginif s1 0 out 8 hff elseif s2 0 s2 1 out 8 hff elsecase in 3 d0 out 8 b11111110 3 d1 out 8 b11111101 3 d2 out 8 b11111011 3 d3 out 8 b11110111 3 d4 out 8 b11101111 3 d5 out 8 b11011111 3 d6 out 8 b10111111 3 d7 out 8 b01111111 endcaseendendmodule 6 15 6 16 CO Q3Q2Q1Q0CTT 注意 异步清零 同步置位 6 16设计一个74161的电路 6 16 modulewytest reset load ctt ctp clk data in out co 习题6 16inputreset load ctt ctp clk input 3 0 data in output 3 0 out outputco reg 3 0 out regco always posedgeclkornegedgereset if reset beginout 4 b0 co 1 b0 endelseif load out data in elseif ctt out out elseif ctp out out elsebeginout out 1 if out 14 co 1 elseco 0 endendmodule 6 16 四级流水线实现的32位加法器 modulewytest clk a b sum cout input 31 0 a b inputclk output 31 0 sum outputcout 最后输出的结果reg 31 0 sum regcout 第一级流水线的输出reg 7 0 fist sum regfirst cout 第一级流水线要缓存的数据 未用的数据缓存reg 7 0 first a 31 24 first a 23 16 first a 15 8 reg 7 0 first b 31 24 first b 23 16 first b 15 8 四级流水线实现的32位加法器 第二级流水线的输出reg 7 0 second sum regsecond cout 第二级流水线要缓存的数据 未用的数据缓存reg 7 0 second a 31 24 second a 23 16 reg 7 0 second b 31 24 second b 23 16 第一级流水线计算结果缓存reg 7 0 first sum 1 第一级流水线计算结果第一次缓存 第三级流水线输出reg 7 0 third sum regthird cout 第三级流水线要缓存的数据 未用的数据缓存reg 7 0 third a 31 24 reg 7 0 third b 31 24 第一级 第二级流水线计算结果缓存reg 7 0 first sum 2 第一级流水线计算结果第二次缓存 reg 7 0 second sum 1 第二级流水线计算结果第一次缓存 四级流水线实现的32位加法器 第一级流水线always posedgeclk begin first cout fist sum a 7 0 b 7 0 cout first a 31 24 a 31 24 first b 31 24 b 31 24 first a 23 16 a 23 16 first b 23 16 b 23 16 first a 15 8 a 15 8 first b 15 8 b 15 8 end 第二级流水线always posedgeclk begin second cout second sum first a 15 8 first b 15 8 first cout second a 31 24 first a 31 24 second b 31 24 first b 31 24 second a 23 16 first a 23 16 second b 23 16 first b 23 16 first sum 1 fist sum end 四级流水线实现的32位加法器 第三级流水线always posedgeclk begin third cout third sum second a 23 16 second b 23 16 second cout third a 31 24 second a 31 24 third b 31 24 second b 31 24 first sum 2 first sum 1 second sum 1 second sum end 第四级流水线always posedgeclk begin cout sum 31 24 third a 31 24 third b 31 24 third cout sum 23 0 third sum second sum 1 first sum 2 endendmodule 四级流水线实现的32位加法器 8x8乘法器实现 modulewytest out a b clk input 7 0 a b inputclk output 15 0 out reg 15 0 out reg 3 0 firsta firstb reg 3 0 seconda secondb wire 7 0 outa outb outc outd always posedgeclk beginfirsta 3 0 a 7 4 seconda 3 0 a 3 0 firstb 3 0 b 7 4 secondb 3 0 b 3 0 end mul4x4m1 outa firsta firstb clk m2 outb seconda firstb clk m3 outc firsta secondb clk m4 outd seconda secondb clk always posedgeclk out outa 8 outb 4 outc 4 outd endmodule 8x8乘法器实现 用另一种方法实现 将8位数字分成4段 每段两位 那么操作数可表示如下 A A1X26 A2X24 A3X22 A4B B1X26 B2X24 B3X22 B4AXB A1X26 A2X24 A3X22 A4 X B1X26 B2X24 B3X22 B4 上式展开后 要做16次2X2的乘法 调用16次lookup函数然后再做移位相加的处理 7 5编写4位并 串转换电路 modulewytest clk rst in out inputclk rst input 3 0 in outputout regout reg 1 0 i always posedgeclk beginif rst begini 2 d0 out 1 d0 endelseif i 3 beginout in i i i 1 endend 模为9的占空比50 的奇数分频 modulewytest RESET CLK COUT inputCLK RESET outputCOUT reg 3 0 m n wireCOUT regCOUT1 COUT2 assignCOUT COUT1 COUT2 always posedgeCLK beginif RESET beginCOUT1 0 输出信号初态为0m 0 计数初值为0end elseif RESET beginif m 8 n 1beginm 0 endelsem m 1 if m 3 N 2 1 5COUT1 COUT1 elseif m 7 N 2COUT1 COUT1 endend always negedgeCLK beginif RESET beginCOUT2 0 n 0 end elseif RESET beginif n 8 beginn 0 endelsen n 1 if n 3 COUT2 COUT2 elseif n 7 COUT2 COUT2 endendEndmodule 模为9的占空比50 的奇数分频 模为9 3的小数分频 分频方法 9分频7次 10分频3次 modulefdiv8 1 clk in rst clk out inputclk in rst outputclk out regclk out reg 3 0 cnt1 cnt1计8分频的次数reg 3 0 cnt2 cnt2为两个分频器的计数值always posedgeclk inorposedgerst beginif rst begincnt1 0 cnt2 0 clk out 0 endelseif cnt1 7 9分频7次beginif cnt2 8 9分频的前8个脉冲的处理begincnt2 cnt2 1 clk out 0 endelse 处理最后一个输入脉冲begincnt2 0 clk out 1 cnt1 cnt1 1 endend 模为9 3的小数分频 elseif cnt1 10 beginif cnt2 9 10分频的前9个脉冲处理begincnt2 cnt2 1 clk out 0 endelsebegincnt2 0 clk out 1 if cnt1 9 cnt1 0 elsecnt1 cnt1 1 endendendendmodule 习题10 3 1001 二进制序列检测器 S0 S1 S2 S3 1 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 RESET modulewytest reset clk in out inputreset clk in outputout regout reg 1 0 state next state parameters0 2 d0 s1 2 d1 s2 2 d2 s3 2 d3 always posedgeclk beginif reset state s0 elsestate next state endalways stateorin case state s0 if in 1 next state s1 elsenext state s0 s1 if in 0 next state s2 elsenext state s1 s2 if in 0 next state s3 elsenext state s1 s3 if in 1 next state s1 elsenext state s0 default next state s0 endcase always stateorin case state s0 if in 1 out 0 elseout 0 s1 if in 0 out 0 elseout 0 s2 if in 0 out 0 elseout 0 s3 if in 1 out 1 elseout 0 default out 0 endcaseendmodule
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!