Verilog刷题笔记16

本文探讨了在Verilog中使用assign和alwaysblocks描述数字电路的不同之处,着重于它们在描述组合逻辑和时钟触发逻辑上的作用,以及wire和reg类型的适用性。作者通过实例展示了两者之间的等效性以及在硬件合成中的注意事项。
摘要由CSDN通过智能技术生成

题目:
Since digital circuits are composed of logic gates connected with wires, any circuit can be expressed as some combination of modules and assign statements. However, sometimes this is not the most convenient way to describe the circuit. Procedures (of which always blocks are one example) provide an alternative syntax for describing circuits.

For synthesizing hardware, two types of always blocks are relevant:

Combinational: always @(*)
Clocked: always @(posedge clk)
Combinational always blocks are equivalent to assign statements, thus there is always a way to express a combinational circuit both ways. The choice between which to use is mainly an issue of which syntax is more convenient. The syntax for code inside a procedural block is different from code that is outside. Procedural blocks have a richer set of statements (e.g., if-then, case), cannot contain continuous assignments, but also introduces many new non-intuitive ways of making errors. *(*Procedural continuous assignments do exist, but are somewhat different from continuous assignments, and are not synthesizable.)

For example, the assign and combinational always block describe the same circuit. Both create the same blob of combinational logic. Both will recompute the output whenever any of the inputs (right side) changes value.
assign out1 = a & b | c ^ d;
always @(*) out2 = a & b | c ^ d;
在这里插入图片描述
在这里插入图片描述
我的解法:

// synthesis verilog_input_version verilog_2001
module top_module(
    input a, 
    input b,
    output wire out_assign,
    output reg out_alwaysblock
);
	assign out_assign=a&b;
    always @(*) out_alwaysblock=a&b;
endmodule

结果正确:
在这里插入图片描述
此题考查两种赋值方法:
两种类型:

output wire out_assign
output reg out_alwaysblock

对应两种不同赋值方法:

	assign out_assign=a&b;
    always @(*) out_alwaysblock=a&b;

关于 wire 与 reg 的说明:赋值语句的左侧必须是 net 类型(例如,wire),而过程赋值的左侧(在 always 块中)必须是变量类型(例如,reg)。这些类型(wire 与 reg)与合成的硬件无关,只是 Verilog 用作硬件仿真语言时遗留下来的语法。

  • 42
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值