Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help in running system verilog code given in SystemVerilog for Verification by Spear

Status
Not open for further replies.

Shilpa-_-Singh

Newbie level 2
Newbie level 2
Joined
Dec 5, 2014
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
13
Hello sir,
I am a newbie to system verilog and I was trying to run the following code given in spears book
Code:
function void init(ref int f[5], input int start);
  foreach (f[i])
    f[i] = i + start;
endfunction
int fa[5];
initial begin
  init(fa, 5);
  foreach (fa[i])
    $display("fa[%0d] = %0d", i, fa[i]);
end

But due to some unfortunate reason it throws errors like "expecting class","unexpected initial"
Can someone please help me in making this code runnable in modelsim? and tell me what should be the output.


Thankyou :)
 

1) Put the entire code as posted inside a module.
2) Run it yourself. ;-)



Sir I did as you said but it is still throwing an error " The task or function 'init' with ref arguments must be automatic."



the code that i used is
Code:
module test();
function void init(ref int f[5], input int start);
  foreach (f[i])
    f[i] = i + start;
endfunction
int fa[5];
initial begin
  init(fa, 5);
  foreach (fa[i])
    $display("fa[%0d] = %0d", i, fa[i]);
end
endmodule


Kindly help!
 

How about I help you help yourself? ;-) Please read this short tutorial on systemverilog functions: https://www.asic-world.com/systemverilog/task_function2.html#Functions

And this one about passing by reference: https://www.asic-world.com/systemverilog/task_function5.html

Actually the error message is big hint on how to fix it...

- - - Updated - - -

Mmmh, I see that the link I gave you does not show that you should be declaring the function as automatic. Well, now you know, you should be declaring that function as automatic because you are passing an argument by reference.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top