HDLbits 刷题 -- Alwaysblock2

学习:

For hardware synthesis, there are two types of always blocks that are relevant:

  • Combinational: always @(*)
  • Clocked: always @(posedge clk)

Clocked always blocks create a blob of combinational logic just like combinational always blocks, but also creates a set of flip-flops (or "registers") at the output of the blob of combinational logic. Instead of the outputs of the blob of logic being visible immediately, the outputs are visible only immediately after the next (posedge clk).

Blocking vs. Non-Blocking Assignment

There are three types of assignments in Verilog:

  • Continuous assignments (assign x = y;). Can only be used when not inside a procedure ("always block").
  • Procedural blocking assignment: (x = y;). Can only be used inside a procedure.
  • Procedural non-blocking assignment: (x <= y;). Can only be used inside a procedure.

In a combinational always block, use blocking assignments. In a clocked always block, use non-blocking assignments. A full understanding of why is not particularly useful for hardware design and requires a good understanding of how Verilog simulators keep track of events. Not following this rule results in extremely hard to find errors that are both non-deterministic and differ between simulation and synthesized hardware.

译:

针对硬件综合,有两种类型的 always 块是相关的:

组合逻辑:always @(*) 时钟控制逻辑:always @(posedge clk)

组合逻辑 always 块创建了一块组合逻辑,就像组合逻辑 always 块一样,但它也在组合逻辑块的输出处创建了一组触发器(或称为“寄存器”)。与组合逻辑块的输出立即可见不同,只有在下一个时钟上升沿(posedge clk)之后,输出才会立即可见。

阻塞赋值与非阻塞赋值 在Verilog中有三种赋值类型:

连续赋值(assign x = y;)。只能在程序("always块")外部使用。 程序化阻塞赋值:(x = y;)。只能在程序内部使用。 程序化非阻塞赋值:(x <= y;)。只能在程序内部使用。 在组合逻辑 always 块中,应使用阻塞赋值。在时钟控制 always 块中,应使用非阻塞赋值。完全理解为什么这样做并不特别有助于硬件设计,并且需要很好地理解Verilog模拟器如何跟踪事件。不遵循这一规则会导致极其难以发现的错误,这些错误既是非确定性的,又在仿真和综合硬件之间存在差异。

练习:

        Build an XOR gate three ways, using an assign statement, a combinational always block, and a clocked always block. Note that the clocked always block produces a different circuit from the other two: There is a flip-flop so the output is delayed.。

用三种方式构建一个异或门(XOR gate):使用赋值语句(assign statement)、组合逻辑 always 块和时钟控制的 always 块。请注意,时钟控制的 always 块产生的电路与另外两个不同:由于存在触发器,输出会有延迟。

// 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 out_assign = a ^ b;
    always@(*) out_always_comb = a ^ b;
    always@(posedge clk) begin
        out_always_ff <= a^b;
    end
   

endmodule

运行结果:

分析:

        主要关注三种赋值方式,以及使用方式;

        另外要注意 Clocked方式,会慢一个时钟输出;

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刚及格的陆拾伍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值