Roj*_*jin 0 verilog computer-architecture
我无法理解这段代码末尾的两行
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}};
Run Code Online (Sandbox Code Playgroud)
如果您不熟悉花括号{},它们是连接运算符.您可以在IEEE Std for Verilog中阅读它们(例如,1800-2009,第11.4.12节).
assign pc_plus_4 = {pc[31],pcinc};
Run Code Online (Sandbox Code Playgroud)
这将MSB pc与所有位pcinc组合在一起以组装pc_plus_4信号.但是,在这种情况下,由于pcinc和pc_plus_4都是32位宽,因此pc[31]被忽略.一个好的linting工具会通知你RHS是33位,LHS是32位,最重要的位将丢失.该行可以更简单地编码为:
assign pc_plus_4 = pcinc;
Run Code Online (Sandbox Code Playgroud)
最后一行是我正在使用的一个模拟器的编译错误.您没有明确声明branch_aadr信号的宽度,并且0未指定常量的宽度.
小智 5
最后一行还包含一个复制操作符,它使用两组花括号.
{13{offset[15]}}
Run Code Online (Sandbox Code Playgroud)
这复制了offset[15]十三次.offset在添加之前,作者似乎正在进行符号扩展pcinc.更好的方法可能是宣布offset签名.
//Three ways to replicate bits
wire [3:0] repeated;
wire value;
//These two assignments have the same effect
assign repeated = {4{value}}; //Replication operator
assign repeated = {value,value,value,value}; //Concatenation operator
//These four taken together have the same effect as the above two
assign repeated[3] = value; //Bit selects
assign repeated[2] = value;
assign repeated[1] = value;
assign repeated[0] = value;
Run Code Online (Sandbox Code Playgroud)