quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Pass by reference

In this arguments are passed by reference and are not copied into the task/function area, rather, a reference to the original argument is passed to the task/function. The task/function can then access the argument data via the reference.

   

space.gif

When the argument is passed by reference, both the caller and the subroutine share the same representation of the argument, so any changes made to the argument either within the caller or the subroutine shall be visible to each other.

   

space.gif

When the formal argument is declared as a const ref, the subroutine cannot alter the variable.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example - Pass by reference
   

space.gif


  1 module function_by_ref ();
  2 
  3 reg [7:0] data      ;
  4 reg       parity_out;
  5 
  6 time      ltime;
  7 
  8 function reg parity (ref reg [7:0] idata, const ref time tdata);
  9  parity = 0;
 10  for (int i= 0; i < 8; i ++) begin
 11     parity = parity ^ idata[i];
 12  end
 13  // We can modify the data passed through reference
 14  idata ++ ;
 15  // Something that is passed as const  ref, can  not be modified
 16  // tdata ++ ; This is wrong
 17 endfunction
 18 
 19 initial begin    
 20   parity_out = 0;
 21   data = 0;
 22   for (int i=250; i<256; i ++) begin
 23     #5  data = i;
 24    ltime = $time;
 25    parity_out = parity (data, ltime);
 26    $display ("Data = %00000000b, Parity = %b, Modified data : %b",
 27       i, parity_out, data);
 28   end
 29    #10  $finish;
 30 end
 31 
 32 endmodule
You could download file function_by_ref.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation Output
   

space.gif

 Data = 11111010, Parity = 0, Modified data : 11111011
 Data = 11111011, Parity = 1, Modified data : 11111100
 Data = 11111100, Parity = 0, Modified data : 11111101
 Data = 11111101, Parity = 1, Modified data : 11111110
 Data = 11111110, Parity = 1, Modified data : 11111111
 Data = 11111111, Parity = 0, Modified data : 00000000
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com