晋江企业网站制作,网站建设多少钱裤,在线图片编辑像素,网站设计是用ps做图吗相关阅读
Verilog基础https://blog.csdn.net/weixin_45791458/category_12263729.html?spm1001.2014.3001.5482 作为一个硬件描述语言#xff0c;Verilog HDL常常需要使用语句描述并行执行的电路#xff0c;但其实在仿真器的底层#xff0c;这些并行执行的语句是有先后顺序…相关阅读
Verilog基础https://blog.csdn.net/weixin_45791458/category_12263729.html?spm1001.2014.3001.5482 作为一个硬件描述语言Verilog HDL常常需要使用语句描述并行执行的电路但其实在仿真器的底层这些并行执行的语句是有先后顺序的然而Verilog标准并没有将这些事件调度的顺序定死而是给予了仿真器厂商一定的自由去实现自己的产品这就导致了设计者如果不遵循一定的编程习惯会导致意想不到的仿真结果下面是一些相关的规则。
1、不要在两个及以上的always或initial结构中对同一个变量赋值 当两个以上的过程结构同时执行时它们之间的执行顺序是不一定的Verilog标准只规定了在一个顺序块(begin end)中的所有语句是按照其先后顺序执行的但并没有规定同一个时间执行的多个结构的执行顺序下面举例详细说明。
//例1
timescale 1ns/1ps
module test();initial $display(The initial_0 execute);initial $display(The initial_1 execute);initial $display(The initial_2 execute);
endmodule 在上例中三个initial结构在0ns时同时执行仿真器执行他们的顺序是不定的但测试表明许多仿真器都选择顺序执行这三个initial结构如下所示。
对于Mentor Modelsim SE输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute对于Aldec Riviera Pro输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute对于Cadence Xcelium输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute对于Mentor Questa输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute对于Synopsys VCS输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute对于Icarus Verilog输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute 虽然看起来仿真器的行为都是一致的但其实这只是一个巧合下面的例子就体现出了各种仿真器对同一段代码之间的不同行为。
//例2
timescale 1ns/1ps
module test();reg a;initial #5 a 1;initial (a) $display(The initial_0 execute);initial (a) $display(The initial_1 execute);initial (a) $display(The initial_2 execute);
endmodule 这段代码的三个initial结构都对事件a敏感所以在5ns时三个initial结构同时被触发而他们的执行顺序是不定的如下所示。
对于Mentor Modelsim SE输出结果为
The initial_2 execute
The initial_1 execute
The initial_0 execute对于Aldec Riviera Pro输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute对于Cadence Xcelium输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute对于Mentor Questa输出结果为
The initial_2 execute
The initial_1 execute
The initial_0 execute对于Synopsys VCS输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execut对于Icarus Verilog输出结果为
The initial_2 execute
The initial_1 execute
The initial_0 execute 下面的代码中仍然体现了同一时间的多个结构的执行顺序是不定的即使触发这些结构的事件在同一时间是有前后关系的。
//例3
timescale 1ns/1ps
module test();reg a, b, c;initial begin#5;a 1;b 1;c 1;endalways (a) $display(The initial_0 execute);always (b) $display(The initial_1 execute);always (c) $display(The initial_2 execute);
endmodule 在5ns时a、b、c先后被赋值为1Verilog标准保证了begin end块中的赋值顺序从上到下。但由这些赋值语句触发的其他always结构呢是否也会按照a、b、c的顺序执行呢
对于Mentor Modelsim SE输出结果为
The initial_2 execute
The initial_1 execute
The initial_0 execute对于Aldec Riviera Pro输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute对于Cadence Xcelium输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute对于Mentor Questa输出结果为
The initial_2 execute
The initial_1 execute
The initial_0 execute对于Synopsys VCS输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execut对于Icarus Verilog输出结果为
The initial_0 execute
The initial_1 execute
The initial_2 execute 依然可以注意到不同仿真器之间的差异为什么不都是按照a赋值always (a)执行b赋值always (b)执行c赋值always (c)执行的顺序执行呢还是那句话Verilog标准只规定了一个顺序块(begin end)中的所有语句是按照其先后顺序执行的并没有保证其他行为。当a赋值后always (a)被调度了但他不一定会在b赋值之前执行有可能在执行完b赋值、c赋值之后再来执行always (a)此时always (b)和always (c)也应该在队列中他们执行的先后顺序是标准没有保证的但需要注意的是最基本的调度者和被调度者的先后关系是无法改变的即always (a)一定在a赋值后b、c亦然。下面是一个经典的两个结构交错执行的例子。
//例4
timescale 1ns/1ps
module test();reg a;wire b;initial begin#1;a 1;#1;a 0;$display(b is %b, b);endassign b a;endmodule 当时间来到1nsa被赋值为1同时触发assign结构对b连续赋值为1。1ns后a被更改为0紧接着打印b的值结果是1还是0呢
对于Mentor Modelsim SE输出结果为
b is 1对于Aldec Riviera Pro输出结果为
b is 1对于Cadence Xcelium输出结果为
b is 1对于Mentor Questa输出结果为
b is 1对于Synopsys VCS输出结果为
b is 0对于Icarus Verilog输出结果为
b is 0 上面的结果显示仿真器可能在执行了a0的赋值后立刻执行被调度的assign连续赋值再返回initial结构执行显示语句也可能继续执行下面的显示语句再去执行被调度的assign连续赋值。 这就给了我们一个启示在改变了一个全组合逻辑的电路的输入后紧接着显示输出可能无法得到更新后的输出。一个更好的做法是给$display语句一定的延时这样就能确保在执行$display前连续赋值已经执行完毕因为不同时间的语句执行是不会产生竞争的。
//例5
timescale 1ns/1ps
module test();reg a;wire b;initial begin#1;a 1;#1;a 0;#0.01 $display(b is %b, b);endassign b a;endmodule