微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微电子和IC设计 > 微电子学习交流 > veriog中的always@语法问题

veriog中的always@语法问题

时间:12-12 整理:3721RD 点击:
最近看到xilinx的某些fifo模型里面有用到always@*用法,而且包含块内是非阻塞赋值,仿真报出警告,这在可综合的语法里不允许,是不是模型设计可以这样随意一些?
可综合语法中always@* 和 always@(*)有使用上有没有什么区别?我知道always@(*)在组合逻辑中应用没有问题。
谢谢!

呕心沥血总结的,区别看例子
Example 1
always @(*) // equivalent to @(a or b or c or d or f)
y = (a & b) | (c & d) | myfunction(f);
Example 2
always @* begin // equivalent to @(a or b or c or d or tmp1 or tmp2)
tmp1 = a & b;
tmp2 = c & d;
y = tmp1 | tmp2;
end
Example 3
always @* begin // equivalent to @(b)
@(i) kid = b; // i is not added to @*
end
Example 4
always @* begin // equivalent to @(a or b or c or d)
x = a ^ b;
@* // equivalent to @(c or d)
x = c ^ d;
end

example2里的tmp1 tmp2出现在敏感列表里有啥实际作用么。。?

当然有了,要不always的begin-end block什么条件下执行?……

tmp1 tmp2是在begin-end block里被赋值的啊,
要说a b c d变化的时候执行begin-end block理解
tmp1 tmp2变化的时候已经在这个block里了,怎么要重新执行一下这个block呢?

要是tmp1 tmp2还会在别的地方赋值的话 那某些工具也会报错的吧。。。

Sorry,没注意看tmp1和tmp2是在begin-end block里被赋值的
我写个例子试试看

@flyelectron
@Rand00m9
写了个例子,发现example2中@*的等同条件只是@(a or b or c or d),并不包含tmp1和tmp2
代码如下:
`timescale 1ns / 10ps
module top();
reg a, b, c, d, tmp1, tmp2, y;
initial begin
    a = 1'b0;
    b = 1'b1;
    c = 1'b1;
    d = 1'b0;
    #5;
    a = 1'b1;
    b = 1'b1;
    c = 1'b1;
    d = 1'b0;
    #5;
    a = 1'b1;
    b = 1'b1;
    c = 1'b1;
    d = 1'b1;
    #0
    $finish;
end
always @* begin
    tmp1 = a & b;
    tmp2 = c & d;
    y = tmp1 | tmp2;
    $display("@ %0t, a = %b, b = %b, c = %b, d = %b, tmp1 = %b, tmp2 = %b, y = %b",
        $time, a, b, c, d, tmp1, tmp2, y);
end
endmodule
运行结果如下:
ncsim> run
@ 500, a = 1, b = 1, c = 1, d = 0, tmp1 = 1, tmp2 = 0, y = 1
@ 1000, a = 1, b = 1, c = 1, d = 1, tmp1 = 1, tmp2 = 1, y = 1
Simulation complete via $finish(1) at time 10 NS + 1
PS:我用simulator的是INCISIV111S010

在initial里给tmp1 tmp2赋值试试。。我这边没有工具现在。。

@flyelectron
@Rand00m9
例子应 @Rand00m9 的要求改了,发现example2中@*的等同条件的确是@(a or b or c or d or tmp1 or tmp2),但是当tmp1和tmp2在同一个block中变化时,always不会触发多次。
学习了,多谢两位!
代码如下:
`timescale 1ns / 10ps
module top();
reg a, b, c, d, tmp1, tmp2, y;
initial begin
    a = 1'b0;
    b = 1'b1;
    c = 1'b1;
    d = 1'b0;
    #2
    tmp1 = 1'b0;
    tmp2 = 1'b1;

    #5;
    a = 1'b1;
    b = 1'b1;
    c = 1'b1;
    d = 1'b0;
    #5;
    a = 1'b1;
    b = 1'b1;
    c = 1'b1;
    d = 1'b1;
    #0
    $finish;
end
always @* begin // equivalent to @(a or b or c or d or tmp1 or tmp2)
    tmp1 = a & b;
    tmp2 = c & d;
    y = tmp1 | tmp2;
    $display("@ %0t, a = %b, b = %b, c = %b, d = %b, tmp1 = %b, tmp2 = %b, y = %b",
        $time, a, b, c, d, tmp1, tmp2, y);
end
endmodule
运行结果如下:
@ 200, a = 0, b = 1, c = 1, d = 0, tmp1 = 0, tmp2 = 0, y = 0
@ 700, a = 1, b = 1, c = 1, d = 0, tmp1 = 1, tmp2 = 0, y = 1
@ 1200, a = 1, b = 1, c = 1, d = 1, tmp1 = 1, tmp2 = 1, y = 1
Simulation complete via $finish(1) at time 12 NS + 1

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top