2015-07-11 71 views
1

我想實例化並使用已在另一個模塊中定義的函數。從Verilog中的另一個模塊調用函數

module simple_function(); 
function myfunction; 
input a, b, c, d; 
begin 
    myfunction = ((a+b) + (c-d)); 
end 
endfunction 
endmodule 

module function_calling(a, b, c, d, e, f);     
input a, b, c, d, e ; 
output f; 
wire f; 
`include "myfunction.v" 
assign f = (myfunction (a,b,c,d)) ? e :0; 
endmodule 

我從http://www.asic-world.com/verilog/task_func1.html 但是這個代碼,當我執行的的ModelSim Altera入門版10.0D一樣,我得到這個錯誤:

Cannot open `include file "myfunction.v". 

我要去哪裏錯了?

回答

1

include指令與在同一位置複製和粘貼該代碼具有相同的效果。從你的代碼看起來你試圖在另一個模塊(function_calling)內部定義一個模塊(simple_function),這是不允許的。

您的功能不需要包含在模塊內。您應該將myfunction.v更改爲僅包含myfunction定義並完全移除simple_function模塊。這樣,當包含myfunction.v時,它與在function_calling中聲明的函數具有相同的效果。

相關問題