decoder3_8
这两天回归书本,继续阅读书上的内容,此时的体会与刚开始学那会的体会是不一样的,比如3_8decoder,之前就认为可以用case来写,而书上有一种更简便的方式来描述,带给你新的思路,既然有新方式可以描述,那就来比较这两者有什么区别。
方法1,利用case语句描述:
module decoder3_8(in,out);
input [:] in;
output [:] out; reg [:] out;
always @(*)
begin
case(in)
'b000: out = 8'b0000_0001;
'b001: out = 8'b0000_0010;
'b010: out = 8'b0000_0100;
'b011: out = 8'b0000_1000;
'b100: out = 8'b0001_0000;
'b101: out = 8'b0010_0000;
'b110: out = 8'b0100_0000;
'b111: out = 8'b1000_0000;
default:out = 'b0000_0000;
endcase
end endmodule
方法2,利用移位方式描述:
module decoder3_8(in,out);
input [:] in;
output [:] out; assign out = 'b1<<in; endmodule
从上面两种方式来看,方法2代码非常的少,一行就搞定,方法1得要好几行才描述完,一般给人感觉就是代码越少消耗的资源也就越少,其实不是的,来看具体比较结果吧:
可以看到除了RTL Viewer不一样外,其他的基本都一样。
在来看看仿真结果吧:
激励文件:
module decoder3_8_top;
reg [:] in;
wire [:] out; initial
begin
in = 'dz;
#;
in = 'd0;
#;
in = 'd1;
#;
in = 'd2;
#;
in = 'd3;
#;
in = 'd4;
#;
in = 'd5;
#;
in = 'd6;
#;
in = 'd7;
#;
end
decoder3_8 u1(
.in(in),
.out(out)
); endmodule
移位方式仿真波形:
case方式仿真波形:

结果是相同的。
decoder3_8的更多相关文章
- Verilog学习笔记简单功能实现(四)...............译码器和编码器
这里以简单的3-8译码器和8-3编码器为例: module decoder3_8(a,out); :]a; :]out; 'b1<<a;/*把最低位的1左移in位(根据in口输入的值)并赋 ...
- Verilog (二) multiplexer and decoder
1 mutiplexer 数据选择器 1) one-bit wide 2-1 mux wire dout = sel? din1 : din0; // conditional continuous ...
- nexys4ddr数码管动态扫描Verilog例程
题目:实现数码管动态扫描功能,将十六个开关的值以十六进制的方式在4个数码管上同时显示出来. `timescale 1ns / 1ps module top( clk, sw, seg, an ); / ...
随机推荐
- Django:之安全、国际化和session
Django 安全 以下是关于Django安全的一些特征,它包括如何使基于Django的网站的一些建议. 关于安全的官方文档:https://docs.djangoproject.com/en/dev ...
- 15.找出如下数组中最大的元素和最小的元素, a[][]={{3,2,6},{6,8,2,10},{5},{12,3,23}}
package com.bao; public class Erweim { public static void main(String[] args) { int[][]a={{3,2,6},{6 ...
- find the closest sum to a target value
problem: given an array of integers including positive and negative, a target value. find 2 numbers ...
- .net项目svn项目管理文件清单
You can add the following files to Visual Studio source control: Solution files (*.sln). Project fil ...
- Ansible6:Playbook简单使用【转】
ansbile-playbook是一系列ansible命令的集合,利用yaml 语言编写.playbook命令根据自上而下的顺序依次执行.同时,playbook开创了很多特性,它可以允许你传输某个命令 ...
- 关于安卓HTTP请求用HttpUrlConnection还是HttpClient好
安卓和JAVA应用开发少不了要提交HTTP请求,而基本上目前有两个实现方式:HttpUrlConnection(即URL.openConnection)和HttpClient. 网上不少人都认为Htt ...
- rm: 无法删除 "xxxxx.o" : 输入/输出错误.
rm: 无法删除 "xxxxx.o" : 输入/输出错误. 碰到无法删除的文件,以为完蛋了,要重装. 后面重启一下就可以了
- Linq分组,linq方法分组
Group在SQL经常使用,通常是对一个字段或者多个字段分组,求其总和,均值等. Linq中的Groupby方法也有这种功能.具体实现看代码: 假设有如下的一个数据集: 01.public class ...
- NSAttributedString in Swift
转载自: https://www.invasivecode.com/weblog/attributed-text-swift/ I have been talking quite a lot in ...
- UITableView使用中的一些刁专问题总结
tableview中cell的系统分隔线问题(分隔线顶满或者缩短) //tableview代理方法,设置系统cell的分隔线 -(void)tableView:(UITableView *)table ...