小编Fra*_* Li的帖子

Verilog:三元运算符与算术右移一起导致意外行为

首先看一下设计右移寄存器的三个代码示例,它允许用户在算术右移或逻辑右移之间进行选择:

例1:

module shiftr (data, shamt, arith, result);

    input [8 - 1:0] data;
    input [3 - 1:0] shamt;
    input arith;
    output [8 - 1:0] result;

    wire [8 - 1:0] arith_shift;

    assign arith_shift = $signed(data) >>> shamt;
    assign result = arith ? arith_shift : (data >> shamt);

endmodule
Run Code Online (Sandbox Code Playgroud)

例2:

module shiftr (data, shamt, arith, result);

    input [8 - 1:0] data;
    input [3 - 1:0] shamt;
    input arith;
    output [8 - 1:0] result;

  assign result = arith ? (($signed(data)) >>> shamt) : …
Run Code Online (Sandbox Code Playgroud)

verilog

4
推荐指数
1
解决办法
63
查看次数

标签 统计

verilog ×1