模块(module), 程序块(program)的区别

2022/6/6 5:21:46

本文主要是介绍模块(module), 程序块(program)的区别,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

文章目录

脑子里的语言是汉语,而编程和表达需要在两种语言切换。program不是项目,中国话叫程序块,module是

为避免仿真和设计竞争问题(race condition),systemverilog中引入了program的概念。
module
program
注意点
区别
module
在verilog中,模块可以用来描述从简单的门元件到复杂的系统 (例如一个微处理器)的任何一种硬件电路。模块除了可以为硬件建模外,也可以用来封装验证平台,在模块内部,我们可以例化采用模块定义的DUT和采用 program或者class封装的验证平台。

program
程序块可以被看作是一个具有特殊执行语义的模块。相当于软件领域。一旦被声明,一个程序块可以在需要的层次位置 (典型情况是顶层)中被实例化,并且它的端口可以像任何其他模块一样。程序块内的类型和数据声明对于程序块的作用范围来讲是本地的,并具有静态的生命周期。当然,我们也可以通过 automatic将程序块声明为自动存储的。

注意点
在程序块中要采用非阻塞赋值语句 (<=)对时钟(clocking_block)中的信号做驱动。
在程序块中的本地变量进行赋值要采用阻塞赋值语句 (=)。
程序块中可以有任务、函数、类和 initial块,但不能有always块。
对封装验证程序的程序块采用 automatic来定义。
程序块可以消除验证平台和设计之间的竞争。
区别
module里可以定义program,而program里不能定义module。
module里不能调用program里定义的task, function,而program可以调用module里定义的task和function;
program里不能例化module,interface以及其它program
program是在Ractive时域执行的,而module在active时域执行的,所以program在module后执行,可以解决竞争冒险现象
若program中有always块,则无法结束运行,可使用 $exit 强行结束

program是用于编写测试激励的,而module是用于编写硬件模块的,一个是写软件程序,一个是硬件电路

 

A module and a program block carry many similarities.

  • Similar to a module, a program block may have zero or more inputs, outputs and inout ports.
  • A program block can contain zero or more initial blocks, cont assignments, generate and specparam statements, concurrent assertions and timunit declarations.
  • Type and data declarations, functions and tasks can be defined within a program block similar to what you can do in a module.
  • A hierarchy can contain any number of program blocks. These program blocks may interact throughtheir ports or may be isolated from one other. This is how modules work too in a design environment.

 

However, the similarities end there. Here are some of the differences.

  • A program block can not contain any always statement, UDP, module, interface or other program. Thus a program block is always a leaf level node in a hierarchy.
  • A program definition can occur within a module as we saw earlier. Obviously, a module can not be defined this way.
  • A program can call a task or function in modules or other programs. But a module can not call a task or function in a program.

However, the biggest difference between a program and a module is the way they handle variable assignments in procedural blocks. We will see in the next section this is where the utility of a program comes into effect.






这篇关于模块(module), 程序块(program)的区别的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程