Verilog刷题[hdlbits] :Always if

编程入门 行业动态 更新时间:2024-10-25 19:34:56

<a href=https://www.elefans.com/category/jswz/34/1767890.html style=Verilog刷题[hdlbits] :Always if"/>

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@(*)beginout_always_comb = a ^ b;end//时钟型always块always@(posedge clk)beginout_always_ff <= a ^ b;end
endmodule

更多推荐

Verilog刷题[hdlbits] :Always if

本文发布于:2023-11-15 19:31:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605079.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Verilog   刷题   hdlbits

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!