- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 Verilog 中制作一个签名比较器。这是代码:
module signedComparator(a0, a1, a2, b0, b1, b2, G, E, L);
input a0, a1, a2, b0, b1, b2;
output reg G, E, L;
always@(a0 or a1 or a2 or b0 or b1 or b2)
begin
if(a2 == 0 && b2 == 0) //both a and b >= 0
begin
L <= {a1,a0} < {b1,b0};
G <= {a1,a0} > {b1,b0};
E <= {a1,a0} == {b1,b0};
end
else if(a2 == 1 && b2 == 0) //a negative, b >= 0
begin
L <= 1;
G <= 0;
E <= 0;
end
else if(a2 == 0 && b2 == 1) //a >= 0, b negative
begin
L <= 0;
G <= 1;
E <= 0;
end
else //both a and b negative
begin
L <= (~{a1,a0} + 1) > (~{b1,b0} + 1);
G <= (~{a1,a0} + 1) < (~{b1,b0} + 1);
E <= (~{a1,a0} + 1) == (~{b1,b0} + 1);
end
end
endmodule
我想知道,向量相加时,中间结果的长度是多少?我担心最后一个案例( L <= (~{a1,a0} + 1) > (~{b1,b0} + 1);
)。 ~{a1,a0}加1时,比较结果是3位长度,还是{1,1} + 1 = {0,0}?是否有文档说明 verilog 中中间结果的数据类型是什么?由于我还不知道正确的术语,因此很难搜索。
最佳答案
我假设这是为了综合,并对您的代码有一些评论。您似乎使用各个位作为模块的输入,然后使用串联来创建向量。您可以通过将端口声明为有符号向量并直接进行比较来避免这种情况。
input signed [2:0] a,b;
...
if(a == b)
...
else if(a > b)
...
else
...
此外,您还使用非阻塞赋值来建模组合逻辑。这些将在您发布的代码中工作,但实际上不应该以这种方式使用。它们通过时钟进程更好地建模同步逻辑。有一个good paper总结了一种良好的综合编码风格。
I am wondering, when adding vectors, what is the length of the intermediate result?
规范为此提供了一个表格,因为它取决于操作数和上下文。
因此,您的比较操作数都将(至少)为 32 位。您可以通过在值前使用勾号来显式分配常量大小。
4'b1 // 0001 Binary 1
4'd1 // 0001 Decimal 1
4'd8 // 1000 Decimal 8
1'b1 // 1 Binary 1
'b1 // The same as 1, tick here only specifies dec/oct/bin format
Is there documentation somewhere for what the data type of intermediate results in verilog will be?
到目前为止,我找到的有关此类详细信息的最佳资源是规范本身,IEEE 1364。
关于verilog - Verilog中算术运算结果的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8015709/
如标题所示,结构 Verilog 和行为 Verilog 之间的主要区别是什么? 最佳答案 根据 IEEE 标准,这些术语没有严格的定义。然而,习惯上,结构 是指使用模块实例来描述设计(尤其是对于较低
我正在尝试简单地转换流程图 state machine进入 Verilog代码。 但是我不知何故被以下内容困住了,因为我对 Verilog 几乎没有任何了解,所以我可能会遗漏一些东西。 状态机检测到
是否可以在 verilog 中参数化位域?本质上,我想使用参数或替代方法来定义位范围。我能想到的唯一方法是使用如下所示的`define,但似乎应该有更好的方法。 `define BITFIELD_SE
初学者在这里。我正在尝试在 Verilog 中编写一个简单的 16 位微处理器并在 Spartan 6 上实现它。 ALU 实现所有有符号操作(根本没有无符号操作)。所有输入都是连线并带有符号。结果存
我写了一些 Verilog 代码,其中部分代码如下: int i; add_bit = 1'b0; for (i = 0; i < add_len; i++)
我需要在我的 Verilog 代码中使用有理数。我寻找了任何资源,但找不到有关此问题的任何信息。如何在 Verilog 中定义有理数。 最佳答案 Verilog 有一个 real用于实数(浮点)数的数
我正在自学verilog。我正在阅读的这本书在介绍章节中指出,要执行除法,我们使用“/”运算符或“%”运算符。后面几章都说除法对于verilog来说太复杂了,不能综合,所以要进行除法就引入了很长的算法
是否可以在 Verilog 中创建 parameter 数组?例如,类似于以下内容: parameter[TOTAL-1 : 0] PARAM_ARRAY = {1, 0, 0, 2} 如果不可能,那
例如,假设我有一个 reg [7:0] myReg我给它赋值 -8'D69 我知道 Verilog 将它存储为 2 的补码,所以它应该存储为 10111011 我现在的问题是是否要对其执行操作,例如
我正在尝试编写一个用于遗传算法的适应度函数,该函数包含指数部分。那么我该如何实现这个函数( e^x ),其中 e :the base=2.7 ,x:exponent 在 verilog HDL 语言中
我在verilog中有一个语句,看起来像integer level = log(N)(其中N是一个参数,级别待确定)但我知道我无法在verilog中执行复杂的数学语句,所以我想知道是否有替代解决方案来
在 Verilog 中,您可以简单地使用模块语法创建模块。如何创建多个模块并调用另一个模块? 我的主模块有以下模块: module Lab7Part1(SW, HEX0, HEX1, HEX2, HE
在使用自上而下的方法在 verilog 中设计电路时,我可以从电路的行为开始,然后定义每个模块中的细节,以构建可综合的结构电路。但我怎么知道我的代码是否可综合呢?是否有任何指南可以遵循来支持 veri
如果我有一个 if 语句,例如: if(risingEdge && cnt == 3'b111) begin ... end 如果risingEdge不为真,它会检查cnt吗? 这在 HDL 内部
我一直在尝试构建一个模块,该模块返回(3 位)输入的二进制补码表示(第一位是符号)。我认为以下代码在概念上是正确的,但我可能遗漏了它的结构:当我尝试编译时,出现以下错误: (vlog-2110) Il
我对 HDL 语言非常陌生。我有一个关于如何对移位寄存器进行编程的问题。 (我知道我转向另一个方向)。为什么本书使用 wire[N-1:0] r_next?我的实现有什么缺点?谢谢 我的第一次尝试如下
郑重声明,我是一个十足的 Verilog 新手。我正在编写一个使用一些双向总线的模块。 inout wire [KEY_SIZE-1:0] prevKey; inout wire [TAG_SIZE-
我进行了搜索以了解 verilog 中的行为代码和数据流代码之间的区别。最后我找不到很好的例子,到处都在讲述他们所做的事情。例如: “它非常简单。名称本身就解释了它们是什么。数据流是描述程序的一种方式
在 Verilog 中,您可以简单地使用模块语法创建模块。您如何创建多个模块并从另一个模块调用一个? 我有以下模块是我的主要模块: module Lab7Part1(SW, HEX0, HEX1, H
我正在学习 verilog 分层事件队列。我对非事件事件有一点疑问。我知道它们是在当前模拟时间完成所有事件事件后执行的。但是我写了一个简单的代码来更好地理解这个概念,但我得到的结果让我感到困惑。这是我
我是一名优秀的程序员,十分优秀!