Verilog练习:HDLBits笔记8

三、Circuits

Combinational logic-Multiplexers

1、2-to-1 Multiplexer

Problem Statement:

Create a one-bit wide, 2-to-1 multiplexer. When sel=0, choose a. When sel=1, choose b.

module top_module( 
    input a, b, sel,
    output out 
);
    always@(*)begin
    	case(sel)
       		0 : out = a;
       		1 : out = b;
    	endcase
    end

endmodule

2、2-to-1 bus Multiplexer 

Problem Statement:

Create a 100-bit wide, 2-to-1 multiplexer. When sel=0, choose a. When sel=1, choose b.

module top_module( 
    input [99:0] a, b,
    input sel,
    output [99:0] out 
);
    always@(*)begin
        case(sel)
            0 : out = a;
            1 : out = b;
        endcase
    end

endmodule

3、9-to-1 Multiplexer 

Problem Statement:

Create a 16-bit wide, 9-to-1 multiplexer. sel=0 chooses a, sel=1 chooses b, etc. For the unused cases (sel=9 to 15), set all output bits to '1'.

module top_module( 
    input [15:0] a, b, c, d, e, f, g, h, i,
    input [3:0] sel,
    output [15:0] out 
);
    always@(*)begin
        case(sel)
            4'd0 : out = a;
            4'd1 : out = b;
            4'd2 : out = c;
            4'd3 : out = d;
            4'd4 : out = e;
            4'd5 : out = f;
            4'd6 : out = g;
            4'd7 : out = h;
            4'd8 : out = i;
            default : out = 16'd65535;
        endcase
    end

endmodule

4、256-to-1 Multiplexer 

Problem Statement:

Create a 1-bit wide, 256-to-1 multiplexer. The 256 inputs are all packed into a single 256-bit input vector. sel=0 should select in[0], sel=1 selects bits in[1], sel=2 selects bits in[2], etc.

module top_module( 
    input [255:0] in,
    input [7:0] sel,
    output out 
);
    
    assign out = in[sel];

endmodule

5、256-to-1 4-bit Multiplexer  

Problem Statement:

Create a 4-bit wide, 256-to-1 multiplexer. The 256 4-bit inputs are all packed into a single 1024-bit input vector. sel=0 should select bits in[3:0], sel=1 selects bits in[7:4], sel=2 selects bits in[11:8], etc.

module top_module( 
    input [1023:0] in,
    input [7:0] sel,
    output [3:0] out 
);

    assign out = in[sel * 4 +: 4];
    
endmodule
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用提供的内容是关于Verilog语法的说明。引用中提供了使用Verilog的应用选项的说明。引用给出了Verilog HDL中规定的四种基本值类型。根据这些引用的内容,可以得出以下回答: Verilog是一种硬件描述语言(Hardware Description Language),用于描述和设计数字电路。它可以用来描述电路的结构、功能和时序等特性。在Verilog中,可以使用不同的语句和操作符来表示逻辑和时序关系,以便实现所需的电路功能。 关于Verilog的应用选项,可以使用命令行工具来对Verilog代码进行格式化。使用特定的命令和选项可以指定要格式化的Verilog文件,以及其他格式化的要求。 在Verilog HDL中,定义了四种基本的值类型:逻辑0或"假"、逻辑1或"真"、未知值和高阻值。这些值类型在语言中有预定义的含义。例如,一个值为Z的表示高阻值,一个值为0的通常表示逻辑0。在门的输入或表达式中,值为Z的通常解释为X。此外,X值和Z值的大小写不敏感,即0x1z与0X1Z表示相同的值。Verilog HDL中的常量由这四种基本值类型组成。 综上所述,Verilog是一种用于描述和设计数字电路的硬件描述语言,可以使用应用选项对Verilog代码进行格式化,而Verilog HDL中定义了四种基本值类型。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [verilog语法中+:和-:用法](https://blog.csdn.net/yh13572438258/article/details/121809886)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [verilog-format:Verilog格式化程序](https://download.csdn.net/download/weixin_42170064/18422664)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Verilog的基础知识](https://blog.csdn.net/qq_38531460/article/details/106872142)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值