Verilog刷题笔记17

题目:

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.

A bit of practice

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.

我的解法:

bash 复制代码
// 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) out_always_ff=a^b;
endmodule

结果正确:

相关推荐
saoys7 分钟前
Opencv 学习笔记:图像卷积操作(锐化核实战 + 数据类型避坑)
笔记·opencv·学习
Coisinilove2 小时前
MATLAB学习笔记——第三章
笔记·学习·matlab
小乔的编程内容分享站2 小时前
C语言笔记一维&二维数组
c语言·笔记
火红色祥云3 小时前
深度学习入门:基于Python的理论与实现笔记
笔记·python·深度学习
Aliex_git3 小时前
gzip 压缩实践笔记
前端·网络·笔记·学习
liuchangng3 小时前
BMAD-METHOD实战笔记_20260213112550
笔记
2501_901147834 小时前
打家劫舍问题的动态规划解法与性能优化笔记
笔记·算法·动态规划
像豆芽一样优秀4 小时前
Easy-Vibe Task02学习笔记
笔记·学习
FPGA小c鸡4 小时前
FPGA Transformer加速完全指南:从模型优化到硬件实现(附实战案例)
深度学习·fpga开发·transformer
Fpga_User4 小时前
项目FPGA类型获取(以xilinx为例)
fpga开发