首页 > 解决方案 > Verilog 模块实例化顺序重要吗?

问题描述

module parity (
a      , // First input
b      , // Second input 
c      , // Third Input
d      , // Fourth Input
y        // Parity  output
);

// Input Declaration
input       a       ;
input       b       ;
input       c       ;
input       d       ;
// Ouput Declaration
output      y      ;
// port data types
wire        a        ;
wire        b        ;
wire        c        ;
wire        d        ;
wire        y        ;
// Internal variables
wire        out_0 ;

wire        out_1 ;

// Code starts Here
xor u0 (out_0,a,b);

xor u1 (out_1,c,d);

xor u2 (y,out_0,out_1);

endmodule // End Of Module parity 

假设我有上面的模块。xor 模块声明的顺序是否重要?如果我像这样重新排序声明:

xor u1 (out_1,c,d);

xor u2 (y,out_0,out_1);

xor u0 (out_0,a,b);

合成电路会一样吗?

标签: verilogsystem-verilog

解决方案


Verilog 语言用于描述连接的类似硬件的元素和算法的行为。这些连接定义了在模拟过程中如何评估元素以及如何合成它们。模拟调度(和硬件行为)基于连接网络中发生的事件。

因此,如果正确连接它们,实例化这些元素的顺序无关紧要。例如

module a(input i, output o);
endmodule

module b(input i, output o);
endmodule

module top(input i, output o);
  a a1(i, t);
  b b1(t, o);
endmodule

一旦模块a a1的输出连接到模块的输入b b1,它的行为将与此处相同:

module top(input i, output o);
  b b1(t, o);
  a a1(i, t);
endmodule

出于可读性原因,您可能更喜欢第一个版本。


推荐阅读