(Verilog) 阻塞型和非阻塞型的assign语句

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中有三种类型的赋值:

连续赋值(continuous assignments)(assign x = y;)。仅在不在过程("always block")中使用时可用。

过程阻塞式赋值:(x = y;)。仅在过程中使用时可用。

过程非阻塞式赋值:(x <= y;)。仅在过程中使用时可用。

在组合型always块中使用阻塞式赋值,在时钟型always块中使用非阻塞式赋值。要完全理解其中原因对于硬件设计并不特别有用,而且需要对Verilog仿真器如何跟踪事件有一定的了解。不遵循此规则会导致非确定性且在仿真和合成的硬件之间不同的极难发现的错误。

参考Verilog语法之六:阻塞赋值与非阻塞赋值 - 知乎 (zhihu.com)

相关推荐
怪小庄吖11 小时前
翻译:How do I reset my FPGA?
经验分享·嵌入式硬件·fpga开发·硬件架构·硬件工程·信息与通信·信号处理
海涛高软1 天前
FPGA同步复位和异步复位
fpga开发
FakeOccupational1 天前
fpga系列 HDL:verilog 常见错误与注意事项 quartus13 bug 初始失效 reg *** = 1;
fpga开发·bug
zxfeng~2 天前
AG32 FPGA 的 Block RAM 资源:M9K 使用
fpga开发·ag32
whik11942 天前
FPGA 开发工作需求明确:关键要点与实践方法
fpga开发
whik11942 天前
FPGA开发中的团队协作:构建高效协同的关键路径
fpga开发
南棱笑笑生2 天前
20250117在Ubuntu20.04.6下使用灵思FPGA的刷机工具efinity刷机
fpga开发
我爱C编程2 天前
基于FPGA的BPSK+costas环实现,包含testbench,分析不同信噪比对costas环性能影响
fpga开发·verilog·锁相环·bpsk·costas环
移知2 天前
备战春招—数字IC、FPGA笔试题(2)
fpga开发·数字ic
楠了个难3 天前
以太网实战AD采集上传上位机——FPGA学习笔记27
笔记·学习·fpga开发