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

结果正确:

相关推荐
三伏5228 分钟前
stm32f103系列手册IIC笔记2
笔记·stm32·嵌入式硬件
鄭郑10 分钟前
【Playwright学习笔记 06】用户视觉定位的方法
笔记·学习
jrlong31 分钟前
DataWhale大模型基础与量化微调task4学习笔记(第 1章:参数高效微调_LoRA 方法详解)
笔记·学习
方安乐32 分钟前
react笔记之useMemo
前端·笔记·react.js
卡布叻_星星42 分钟前
后端笔记之Maven配置以及解决Maven中央仓库没有的依赖
笔记
Jackchenyj43 分钟前
基于艾宾浩斯记忆曲线的AI工具实战:ShiflowAI助力高效知识沉淀
人工智能·笔记·信息可视化·智能体
傻小胖44 分钟前
5.BTC-实现-北大肖臻老师客堂笔记
笔记·区块链
鄭郑1 小时前
【Playwright学习笔记 07】其它用户视觉定位的方法
笔记·学习
mjhcsp2 小时前
[笔记] 线性规划 学习笔记
笔记·学习
2501_937798392 小时前
2026企业AI数字资产管理平台评测:谁在定义下一代无形资产?
笔记