【问题标题】:i can't understand the following verilog code我无法理解以下verilog代码
【发布时间】:2011-09-06 02:00:27
【问题描述】:

这段代码末尾的两行我看不懂

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}};

【问题讨论】:

  • 你到底卡在哪里了?

标签: verilog computer-architecture


【解决方案1】:

如果您不熟悉花括号{},它们是连接运算符。您可以在 IEEE Std for Verilog 中了解它们(例如,1800-2009,第 11.4.12 节)。

assign pc_plus_4 = {pc[31],pcinc};

这将pc 的MSB 与pcinc 的所有位连接起来以组装pc_plus_4 信号。然而,在这种情况下,由于pcincpc_plus_4 都是32 位宽,pc[31] 被忽略。一个好的 linting 工具会通知您 RHS 是 33 位,LHS 是 32 位,并且最高有效位将丢失。该行可以更简单地编码为:

assign pc_plus_4 = pcinc;

最后一行是我正在使用的一个模拟器的编译错误。您没有明确声明branch_aadr 信号的宽度,0 常量的宽度未指定。

【讨论】:

    【解决方案2】:

    最后一行还包含一个复制运算符,它使用两组花括号。

    {13{offset[15]}}
    

    这会复制位 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-11
      • 2017-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多