这两天回归书本,继续阅读书上的内容,此时的体会与刚开始学那会的体会是不一样的,比如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. Java C# .net 和 C C++ 跨平台的区别

    当前主流的手机平台很多,而各个主流的平台的语言支持大同小异:如 1.windows系统WP8上主要支持 VB, C#, c/c++, 2.苹果系统ios上支持 object-c, c/c++ 3.an ...

  2. 读入一行字符给string类型

    小技巧 string ss: getline(cin,ss):

  3. python的历史与优劣

    历史 Python的创始人是Guido van Rossum,在发明Python语言之前Guido曾参与过一门称作ABC的语言的设计,ABC是专门为非专业程序员设计的:Guido在Python语言的设 ...

  4. wpa_supplicant_8_ti hostapd wpa_supplicant TI 官方的wpa_supplicant hostapd 移植到linux

    在移植 wpa_supplicant_8_ti 的时候碰到很多头文件找不到.然后参考了下面的博客 http://blog.csdn.net/penglijiang/article/details/85 ...

  5. table详解

    1.tr 元素定义表格行,th 元素定义表头,td 元素定义表格单元. tr内是th还是td可由自己定义,th,td可存在于任一行,th与td的区别在与th字体更粗 2.定义一个table默认有bor ...

  6. MSG 结构

    MSG 消息结构 在 Windows 程序中,消息是由 MSG 结构体来表示的. 结构原型: typedef struct tagMSG { HWND   hwnd; UINT   message; ...

  7. WPF(x:Null 使用)

    <Window x:Class="TestOfNull.MainWindow" xmlns="http://schemas.microsoft.com/winfx/ ...

  8. php des 加密类

    <?php/** *@see Yii CSecurityManager; */class Des{ public static function encrypt($data,$key){ $mo ...

  9. Android Camera(一)

    最近老大交给了一个任务,说是要在本地视频端很够调节摄像头焦距. 碰到了一些问题: 1.手机支不支持摄像头变焦 2.系统自带摄像软件可以变焦,但是自己编写的程序不支持变焦, 这个问题网上也有很多童鞋碰到 ...

  10. 分布式数据库Cobar

    Cobar简介: Cobar是关系型数据库的分布式处理系统,它可以在分布式的环境下看上去像传统数据库一样为您提供海量数据服务. 产品在阿里巴巴B2B公司已经稳定运行了3年以上. 目前已经接管了3000 ...