Verilog中执行位检测

  • 本文关键字:执行 Verilog verilog
  • 更新时间 :
  • 英文 :


刚开始了解Verilog。无论如何,我不明白为什么我的代码不输出溢出到进位cout。所以8'h~42 + 8'h45 + 1'b1 = 9'h103。但是,我似乎无法在cout中获得溢出(如下面的代码所示)。第9位被截断。我得到的是003(执行位仍然是0),而不是103。我不知道我做错了什么。希望有人能帮忙!

注-Matrix_AMatrix_B的十六进制值来自COE文件,分别为42和45。

wire [0:0] cout;
wire    [7:0] matrix_A;
wire    [7:0] matrix_B;
wire [7:0] matrix_BA;
assign {cout,matrix_BA} = (~matrix_A + matrix_B + 1'b1);

在Edaplayground测试。我看不出有什么问题......

编辑:实际上,我的例子和你的有点不同。重写设计和测试台给了我一个提示:当你在assign中添加这三个组件时,它们都是"促进"的。到9位,但是当你对matrix_A负时,提升的位也被负。
~42h + 45h + 1 = ~01000010 + 01000101 + 1 = (promoted to 9 bits) =
~001000010 + 001000101 + 000000001 = (applying negation) = 
110111101 + 001000101 + 000000001 = 1000000011 (a 10 bit result, which is
truncated to 9 bits) = 000000011 , making your carry to be 0.

试试这个:

assign {cout,matrix_BA} = {1'b0, ~matrix_A} + {1'b0, matrix_B} + 9'b1;

您可以测试自己:https://www.edaplayground.com/x/iGQP

最新更新