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

结果正确:

相关推荐
乘风~&1 小时前
fpga助教面试题
fpga开发
红花与香菇2____2 小时前
【学习笔记】Cadence电子设计全流程(二)原理图库的创建与设计(上)
笔记·嵌入式硬件·学习·pcb设计·cadence·pcb工艺
拥有一颗学徒的心4 小时前
鸿蒙第三方库MMKV源码学习笔记
笔记·学习·性能优化·harmonyos
俊哥V8 小时前
[笔记.AI]如何判断模型是否通过剪枝、量化、蒸馏生成?
人工智能·笔记
【云轩】11 小时前
用DeepSeek零基础预测《哪吒之魔童闹海》票房——从数据爬取到模型实战
经验分享·笔记
此去经年。11 小时前
I2C学习笔记-软件模拟I2C
笔记·单片机·学习
汇能感知11 小时前
汇能感知的光谱相机/模块产品有哪些?
经验分享·笔记·科技
安和昂13 小时前
effective-Objective-C第六章阅读笔记
开发语言·笔记·objective-c
Hcoco_me13 小时前
HDLBits ——> Building Larger Circuits
fpga开发
雅俗共赏10014 小时前
提升信息检索准确性和效率的搜索技巧
笔记·搜索引擎