function函数的使用
生活随笔
收集整理的這篇文章主要介紹了
function函数的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
function函數的使用
規則:
注意:
可綜合性問題:
函數每一次調用都被綜合為一個獨立的組合邏輯電路塊。
module tryfunct(clk,n,result,reset);output [31 : 0] result;input [3 : 0] n;input reset,clk;reg [31 : 0] result;always@(posedge clk) beginif(!reset)result <= 0;elsebeginresult <= n*factorial(n)/((n*2)+1);end //verilog在整數除法運算結果中不考慮余數 endfunction [31 : 0] factorial;//函數定義,返回的是一個32位的數input [3:0] operand;//輸入只有一個4位的操作數reg [3:0] index;//函數內部計數用中間變量beginfactorial = operand ? 1 : 0;//先定義操作數為零時函數的輸出為零,不為零時為1for(index = 2;index <= operand ; index = index +1)factorial = index * factorial; //表示階乘的算術迭代運算end endfunctionendmodule歡迎關注我,關于FPGA的問題歡迎留言討論!
總結
以上是生活随笔為你收集整理的function函数的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用task和电平敏感的always快设
- 下一篇: begin:块名