UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Newbie vbpatel2003
Newbie
2,534 Views
Registered: ‎10-09-2013

Problem Passing Values to a function in Verilog

Assuming I have a 3x3 array of integer stored in arr1.When i try to call a function and pass the values is get error

for(i=0;i<3;i=i+1) begin

 for (j=0;j<3;j=j+1)begin

$display("passed value: %d %d" ,i,j);

result = func(i,j);

$display("result : %d",result);

end

end

 

function func;

input i,j;

begin

for(m=0;m<2;m=m+1)begin

for(n=0;n<2;n=n+1)begin

$display(received value : %d %d",i,j);

func = 1;

end

end

endfunction

 

 

the two display func prints different values. I can't figure out the error

0 Kudos
1 Reply
Instructor
Instructor
2,515 Views
Registered: ‎08-14-2007

Re: Problem Passing Values to a function in Verilog

It's not clear what you're trying to do and what "error" you get.

 

I don't see arr1 anywhere in the posted code.

 

You didn't say what the error was.

 

Your function uses loop variables m and n, but prints out the value of i and j.  I imagine it should print the same values 9 times.  Is that the "error you're talking about?

 

On another note.  I see this a lot in these forums.  Your code is not indented.  My guess is that your text editor is using tab characters for indentation, and these are removed when the text is pasted into the post.  If your text editor supports it (most do) you should set it to replace tabs with spaces.  Then pasting the code would show the indentation as you see it.  It also keeps your code formatted the same if someone else opens it in a different editor, or even the same editor with different tab settings.

-- Gabor
0 Kudos