从另一个 Verilog 模块调用任务

编程入门 行业动态 更新时间:2024-10-28 02:27:24
本文介绍了从另一个 Verilog 模块调用任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试学习 Verilog 并且我有一个 Verilog 模块,我想做的是调用另一个文件并从我当前的模块中运行它.

I'm trying to learn Verilog and I have a Verilog module and what I wish to do is then call another file and run that from within my current module.

所以我的模块如下:

module maths();
//register etc details
initial begin

`include "add.v"

end
endmodule

我从 maths 模块调用的 add.v 文件就像:

and my add.v file that is being called from the maths module is like:

task add;
    A = $random;
    B = $random;
    C = A + B;
    $display("Answer: %d", C);
endtask

但我从任务文件中收到错误near "task": syntax error, unexpected "task"near "endtask": syntax error, unexpected "endtask".

But I am receiving the errors from the task file near "task": syntax error, unexpected "task" and near "endtask": syntax error, unexpected "endtask".

我在如何调用任务中阅读了答案来自 Verilog 中的单独模块? 但是那里给出的关于需要从初始块或始终块中调用任务的答案没有帮助,因为它位于模块中的初始块内.

I read the answer at How to call tasks from a separate module in Verilog? but the answer given there about needing to call the task from within an initial or always block hasn't helped because it is within an initial block in the module.

我哪里出错了?

推荐答案

就像 Serge 所说的,始终将您的文件包含在文件的开头,就在模块语句之前.

Like Serge said, always include your files in the beginning of the file, right before the module statement.

`include "add.v"

module maths();
//register etc details
initial begin
    add;
end
endmodule

至于问题,您在添加任务中缺少开始结束语句.任务总是需要这两个语句来包装你的任务代码.

As for the problem, you are missing begin-end statements in the add task. Tasks always need these two statements to wrap your task code.

所以,这应该有效:

reg A, B, C;

task add;
begin
    A = $random;
    B = $random;
    C = A + B;
    $display("Answer: %d", C);
end
endtask

不要忘记 A、B、C 声明 :) !

Don't forget about A, B, C declarations :) !

这篇关于从另一个 Verilog 模块调用任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 09:55:10,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   Verilog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!