HDL—Verilog Language—Procedures—If statement

这里开始使用一个新的语法if

always @(*) begin
    if (condition) begin
        out = x;
    end
    else begin
        out = y;
    end
end
assign out = (condition) ? x : y;

这两个语句的作用是一样的

Build a 2-to-1 mux that chooses between a and b. Choose b if both sel_b1 and sel_b2 are true. Otherwise, choose a. Do the same twice, once using assign statements and once using a procedural if statement.

构建一个2对1的mux,在a和b之间进行选择。如果sel_b1和sel_b2都为true,则选择b。否则,选择a。执行相同的操作两次,一次使用assign语句,另一次使用过程性if语句。

sel_b1sel_b2

out_assign

out_always

00a
01a
10a
11b

// synthesis verilog_input_version verilog_2001
module top_module(
    input a,
    input b,
    input sel_b1,
    input sel_b2,
    output wire out_assign,
    output reg out_always   );
    assign out_assign = ((sel_b1 == 1)&&(sel_b2 == 1)) ? b : a;
    always@(*)begin
        if((sel_b1 == 1)&&(sel_b2 == 1))
            out_always <= b;
        else
            out_always <= a;
    end
endmodule

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值