Verilog刷题[hdlbits] :Always if

题目:Always if

An if statement usually creates a 2-to-1 multiplexer, selecting one input if the condition is true, and the other input if the condition is false.
if语句通常创建一个2- to -1多路复用器,如果条件为真,则选择其中一个输入,如果条件为假,则选择另一个输入。
在这里插入图片描述
This is equivalent to using a continuous assignment with a conditional operator:
这相当于使用带有条件运算符的连续赋值:

assign out = (condition) ? x : y;

However, the procedural if statement provides a new way to make mistakes. The circuit is combinational only if out is always assigned a value.
但是,过程if语句提供了一种新的方式来犯错误。电路只有在out总是被赋值时才是组合的。

A bit of practice

一些实践

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-to-1的多路复用器,在sel_b1和sel_b2都为真时选择b,否则选择a。使用assign语句和过程if语句各做一次。
在这里插入图片描述

上面给出了如何通过assign利用 ? : 和always利用i =f语句实现多路复用器,

// synthesis verilog_input_version verilog_2001
module top_module(
    input clk,
    input a,
    input b,
    output wire out_assign,
    output reg out_always_comb,
    output reg out_always_ff   );
	
    //assign语句
    assign out_assign = a ^ b;
    //组合型always块
    always@(*)
        begin
            out_always_comb = a ^ b;
        end
    //时钟型always块
    always@(posedge clk)
       	begin
            out_always_ff <= a ^ b;
        end
endmodule
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值