这两天回归书本,继续阅读书上的内容,此时的体会与刚开始学那会的体会是不一样的,比如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的更多相关文章

  1. Verilog学习笔记简单功能实现(四)...............译码器和编码器

    这里以简单的3-8译码器和8-3编码器为例: module decoder3_8(a,out); :]a; :]out; 'b1<<a;/*把最低位的1左移in位(根据in口输入的值)并赋 ...

  2. Verilog (二) multiplexer and decoder

    1  mutiplexer 数据选择器 1)  one-bit wide 2-1 mux wire dout = sel? din1 : din0; // conditional continuous ...

  3. nexys4ddr数码管动态扫描Verilog例程

    题目:实现数码管动态扫描功能,将十六个开关的值以十六进制的方式在4个数码管上同时显示出来. `timescale 1ns / 1ps module top( clk, sw, seg, an ); / ...

随机推荐

  1. HDU 2544 最短路(dijkstra+邻接矩阵)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> using namespace std; const int INF=10e7; ...

  2. hdu_5680_zxa and set(想法题)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5680 题意: 问题描述 zxa有一个集合A=\{a_1,a_2,\cdots,a_n\}A={a​1​ ...

  3. php添加gd

    一 GD简介: php处理图形的扩展库,提供了一系列用来处理图片的API.如果开发过程中发现有页面验证码不能显示,则要考虑检查phpinfo(),是否支持GD库. 二 思路: 网上发现添加GD库的方法 ...

  4. kvm and virtualbox running side by side

    http://dedoimedo.com/computers/kvm-virtualbox.html

  5. drupal错误: Maximum execution time of 240 seconds exceeded

    drupal7.5安装完成,导入汉化包时,出现错误: Fatal error: Maximum execution time of 240 seconds exceeded in D:\phpweb\ ...

  6. 【SQL】SQL

    SQL基础 本文参照:http://www.w3school.com.cn/sql/ SQL 结构化查询语言(Structured Query Language). 对于大小写不敏感. SQL 使用单 ...

  7. ios开发使用lipo命令合并真机库和模拟器库

    在开发ios时,我们经常会遇到编译两套库文件,使用模拟器时链接模拟器库,使用真机时使用真机库,这样操作会对后期的维护带来麻烦,所以Apple提供了一个把多个不同平台的.a库文件合并成一个适用于多平台的 ...

  8. 。net MVC 序列化 反序列化

           序列化 (Serialization)将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写入到临时或持久性存储区.以后,可以通过从存储区中读取或反序列化对象 ...

  9. iOS8.0以后的相册

    在 iOS 8.0 后, 使用the Photos framework 代替 the Assets Library framework , The Photos framework 提供更特色和更好的 ...

  10. iOS进阶推荐的书目

    <Effective Objective-C 2.0:编写高质量iOS与OS X代码的52个有效方法>([英]Matt Galloway) 很多面试题有涉及 <IOS数据库应用高级编 ...