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 ); / ...
随机推荐
- Perl资料
一 官网 http://www.perl.org/ 三 资料 http://www.slideshare.net/ggilmour/perl-development-sample-courseware ...
- linq any() all() 返回true 或者false
一.any()只要有一个符合条件就返回true static void Main(string[] args) { //any 有符合条件的就返回true ,,,,,,,,,}; ); Console ...
- 文件系统满的话(filesystem full),该如何处理。
#!/bin/bash function ergodic(){ ` do "/"$file ] then ergodic $"/"$file else loca ...
- Food on the Plane
Food on the Plane time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Apache 的常见问题
Apache "No services installed"问题的处理以及Apache提示 the requested operation has failed而无法启动 安装完 ...
- 在Activity之间使用Intent传值和Bundle传值的区别和方式
两者本质上没有任何区别.Bundle只是一个信息的载体 将内部的内容以键值对组织 Intent负责Activity之间的交互 自己是带有一个Bundle的Intent.putExtras(Bundle ...
- [转]startActivityForResult的用法和demo
有时候我们需要把A activity提交数据给B activity处理,然后把结果返回给A 这种方式在很多种情况需要用到,比如我应用的程序需要有拍照上传的功能. 一种解决方案是 我的应用程序 〉调 ...
- 屏幕的尺寸(厘米)、屏幕分辨率(像素)、PPI它们之间是什么关系
屏幕的尺寸(厘米).屏幕分辨率(像素).PPI它们之间是什么关系? 添加评论 分享 赞同2反对,不会显示你的姓名 知乎用户,数据ETL,UNITY3D 刘大侠.如果 赞同 以iphone4 为例,分辨 ...
- ubuntu服务器移植步骤
1.安装LAMP套件 1 tasksel 2.安装FTP工具 http://www.cnblogs.com/esin/p/3483646.html 3.安装PHPMyAdmin 1)安装 1 apt- ...
- PAT (Advanced Level) 1102. Invert a Binary Tree (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...