这些赋值语句有什么作用?
我无法理解这段代码末尾的两行:
input [15:0] offset ;
output [31:0] pc;
output [31:0] pc_plus_4;
reg [31:0] pc;
wire [31:0] pcinc ;
assign pcinc = pc +4 ;
assign pc_plus_4 = {pc[31],pcinc};
assign branch_aadr = {0,pcinc + {{13{offset[15]}},offset[15:0],2'b00}};
I can't understand the two lines at the end of this code:
input [15:0] offset ;
output [31:0] pc;
output [31:0] pc_plus_4;
reg [31:0] pc;
wire [31:0] pcinc ;
assign pcinc = pc +4 ;
assign pc_plus_4 = {pc[31],pcinc};
assign branch_aadr = {0,pcinc + {{13{offset[15]}},offset[15:0],2'b00}};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不熟悉花括号
{}
,它们是连接运算符。您可以在 IEEE Std for Verilog 中了解它们(例如,1800-2009,第 11.4.12 节)。这会将
pc
的 MSB 与pcinc
的所有位连接起来,以组合pc_plus_4
信号。然而,在这种情况下,由于pcinc
和pc_plus_4
都是 32 位宽,因此pc[31]
被忽略。一个好的 linting 工具会通知您 RHS 是 33 位,LHS 是 32 位,并且最高有效位将丢失。该行可以更简单地编码为:最后一行是我正在使用的一个模拟器的编译错误。您没有显式声明
branch_aadr
信号的宽度,并且0
常量的宽度未指定。If you are unfamiliar with curly braces
{}
, they are concatenation operators. You can read about them in the IEEE Std for Verilog (for example, 1800-2009, Section 11.4.12).This concatenates the MSB of
pc
with all bits ofpcinc
to assemble thepc_plus_4
signal. However, in this case, sincepcinc
andpc_plus_4
are both 32 bits wide,pc[31]
is ignored. A good linting tool will notify you that the RHS is 33 bits and the LHS is 32 bits, and that the most significant bit will be lost. The line can be more simply coded as:The last line is a compile error for one simulator I'm using. You did not explicitly declare the width of the
branch_aadr
signal, and the width of the0
constant is unspecified.最后一行还包含一个复制运算符,它使用两组花括号。
这将复制位
offset[15]
十三次。看起来作者在将offset
添加到pcinc
之前对其进行了符号扩展。更好的方法可能是将offset
声明为有符号的。The last line also contains a replication operator, which uses two sets of curly braces.
This replicates the bit
offset[15]
thirteen times. It looks like the author is doing a sign extension onoffset
before adding it topcinc
. A better way might be to declareoffset
as signed.