Verilog 中的大括号是什么意思?
我很难理解 Verilog 中的以下语法:
input [15:0] a; // 16-bit input
output [31:0] result; // 32-bit output
assign result = {{16{a[15]}}, {a[15:0]}};
我知道 assign
语句将使用电线和组合逻辑将某些内容连接到 result
总线,但是这是怎么回事大括号和 16{a[15]}
?
I am having a hard time understanding the following syntax in Verilog:
input [15:0] a; // 16-bit input
output [31:0] result; // 32-bit output
assign result = {{16{a[15]}}, {a[15:0]}};
I know the assign
statement will wire something up to the result
bus using wires and combinational logic, but what's up with the curly braces and 16{a[15]}
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大括号表示串联,从左侧的最高有效位 (MSB) 到右侧的最低有效位 (LSB)。您正在创建一个 32 位总线(结果),其 16 个最高有效位由 a 总线的第 15 位(MSB)的 16 个副本组成,其 16 个最低有效位仅由 a 总线组成(这种特殊结构已知作为符号扩展,例如需要右移负数以 two'scomplement 形式并保持其负数而不是引入零MSBit)。
就其价值而言,
a[15:0]
周围的嵌套大括号是多余的。The curly braces mean concatenation, from most significant bit (MSB) on the left down to the least significant bit (LSB) on the right. You are creating a 32-bit bus (result) whose 16 most significant bits consist of 16 copies of bit 15 (the MSB) of the a bus, and whose 16 least significant bits consist of just the a bus (this particular construction is known as sign extension, which is needed e.g. to right-shift a negative number in two's complement form and keep it negative rather than introduce zeros into the MSBits).
For what it's worth, the nested curly braces around
a[15:0]
are superfluous.正如马特所说,花括号用于连接。
16{a[15]}
周围的额外大括号是复制运算符。它们在 IEEE Verilog 标准文档 (Std 1364-2005) 的“5.1.14 连接”部分中进行了描述。相同
与 以位元组形式
,与以下相同:
As Matt said, the curly braces are for concatenation. The extra curly braces around
16{a[15]}
are the replication operator. They are described in the IEEE Standard for Verilog document (Std 1364-2005), section "5.1.14 Concatenations".is the same as
In bit-blasted form,
is the same as: