Verilog 中如何使用函数?

编程入门 行业动态 更新时间:2024-10-20 16:50:16
本文介绍了Verilog 中如何使用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在我的 FPGA/Verilog 课程中,我的教授只介绍了函数.

In my FPGA/Verilog course, my professor just went over functions.

他是说在函数中,你按程序编写代码.然后,当你想调用这个函数时,你可以在一个 always 块中调用它(即程序化),或者你可以用赋值语句调用它.

He was saying that within functions, you write the code procedurally. Then, when you want to call the function, you can either call it within an always block (ie, procedurally), or you can call it with an assign statement.

我不明白如何使用过程代码编写函数,然后连续调用.

It doesn't make sense to me how a function can be written with procedural code, but then be called continuously.

如果有人对此(可能)基本问题有任何见解,不胜感激.

If anyone has any insight to this (probably) basic question, it is much appreciated.

推荐答案

它与组合逻辑块几乎完全相同.你这样写,但它被合成为完全不同的东西.考虑以下几点:

It's pretty much exactly the same as combinational logic blocks. You write it that way, but it's synthesized into something completely different. Consider the following:

always @* begin
    a = b + c;
    d = b + a;
end

always @(posedge clk) begin
    out <= d + in; 
end

这与以下内容完全相同:

This is exactly the same thing as:

function integer calc_d(integer b, integer c) begin
    integer a;
    integer d;
    a = b + c;
    d = b + a;
    calc_d = d; 
end
endfunction

always @(posedge clk) begin
    out <= calc_d(b, c) + in;
end

这篇关于Verilog 中如何使用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 13:25:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1410146.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   函数   Verilog

发布评论

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

>www.elefans.com

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