【问题标题】:Why is this verilog relational statement returning true?为什么这个 verilog 关系语句返回 true?
【发布时间】:2014-02-15 21:14:42
【问题描述】:

我有一个名为 sin_hall2 的 9 位有符号线。

此语句返回 true。 sin_hall2[8:0]>9'd1.

当我查看我的模拟时,sin_hall2=-169。我假设这是verilog处理比较负数的方式,但我做错了什么。当我执行 sin_hall2[8:0]>9'sh001 时,我会收到相同的结果。

【问题讨论】:

  • 请显示所有相关代码,包括sin_hall2的定义

标签: comparison operators verilog relational


【解决方案1】:

带符号的数字使用二进制补码格式。也就是说,如果解释为无符号,它们将显示为大数字,即无符号数字范围的后半部分。

如果比较的任何部分是无符号的,则比较是无符号的。 选择位宽,即使整个范围都是无符号的

reg signed [8:0] sin_hall2;

initial begin
  sin_hall2 = -9'd169 ;
  $display( "Comparison unsigned : %b ", sin_hall2 > 9'd1 );
  $display( "Comparison cast     : %b ", sin_hall2 > $signed(9'd1) );
  $display( "Comparison signed   : %b ", sin_hall2 > 9'sd1 );
  $display( "Comparison signed [8:0]: %b ", sin_hall2[8:0] > 9'sd1 );
end

返回:

# Comparison unsigned : 1 
# Comparison cast     : 0 
# Comparison signed   : 0
# Comparison signed [8:0]: 1 

Example on EDA Playground.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2011-09-06
    • 1970-01-01
    相关资源
    最近更新 更多