# Use of a bit from a packed array as a ref to task

**URL:** <https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, systemverilog-Arrays-packedarrays-unpackedarrays\
**Created:** [September 9, 2019, 12:19pm UTC](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522 "2019-09-09T12:19:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaygueta](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@shaygueta](https://verificationacademy.com/forums/u/shaygueta)\
**Post date:** [September 9, 2019, 12:19pm UTC](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/1 "2019-09-09T12:19:46Z")

</div>

Hello,  
I have a task that receives a logic as a ref, e.g. :  
task MyTask(ref logic ref\_input)  
I send this task signals from an interface. If the signal is a single bit it works OK, but I cannot use a one bit slice from a packed array as input. i.e. :  
interface myInterface  
logic myBit;  
logic [7:0] myByte;  
…

MyTask(myBit); //works OK  
MyTask(MyByte[0]); //causes elaboration error vsim-8465  
MyTask(MyByte[0:0]); //also causes elaboration error vsim-8465

My Question is :  
How to convert the input MyByte[0] to appropriate expression(without defining another signal and assigning myByte[0] to it) ?  
Thanks

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [September 9, 2019, 2:25pm UTC](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/2 "2019-09-09T14:25:50Z")

</div>

_In reply to [shaygueta](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522):_

SystemVerilog does not allow a select of a packed array to be passed by reference. Do you really need pass by reference, or will input or output work for you?

---

<div class="post-metadata">

**Author:** ![shaygueta](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@shaygueta](https://verificationacademy.com/forums/u/shaygueta)\
**Post date:** [September 10, 2019, 5:02am UTC](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/3 "2019-09-10T05:02:34Z")

</div>

Hi,  
Yes, I need to pass it by ref, because the task waits for the signal to change value

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [September 10, 2019, 5:15am UTC](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/4 "2019-09-10T05:15:13Z")

</div>

_In reply to [shaygueta](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/3):_

Can you pass then entire byte by ref to the task, then select the bit inside the task? You can add an extra argument that indicates which bit to select.

---

<div class="post-metadata">

**Author:** ![shaygueta](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@shaygueta](https://verificationacademy.com/forums/u/shaygueta)\
**Post date:** [September 10, 2019, 8:18am UTC](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/5 "2019-09-10T08:18:54Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/4):_

Hi,  
No,because what I want is a general task. Sometimes the signal I will send is a single bit, and in other cases it will be a single bit from an array(that can be either packed or unpacked).In such a case, I cannot assume I know the size of the array in advance.  
i.e. I might need :  
logic myBit;  
logic [7:0] myByte;  
logic [31:0] myWord;  
…

MyTask(myBit,0); //Argument is the signal  
MyTask(MyByte,6); //Argument is bit #6 of the signal  
MyTask(MyWord,18); //Argument is bit #18 of the signal

in such a case, what will be the task definition?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [September 10, 2019, 3:14pm UTC](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/6 "2019-09-10T15:14:31Z")

</div>

_In reply to [shaygueta](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/5):_

It would help to have a lot more details about what you are trying to accomplish, otherwise we are going to keep iterating.

You can place your task inside a parametrized class

```verilog
class MyClass #(int size);
static MyTask(ref logic [size-1:0] signal, int position);
...
endtask

MyClass#($bits(MyBit))::Mytask(MyBit,0);
MyClass#($bits(MyByte))::Mytask(MyByte,6);
MyClass#($bits(MyWord))::Mytask(MyWord,18);

```

If you only need to be informed about a changing bit, you can create an event, and pass that event to the task

```verilog
task Mytask(event expr);
  ...
  @expr ...
endtask

fork
  event e;
  @mybit ->e;
  Mytask(e);
join_none
fork
  event e;
  @myByte[6] ->e;
  Mytask(e);
join_none

```

---

<div class="post-metadata">

**Author:** ![kangrh007](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/k/b782af/32.png) [@kangrh007](https://verificationacademy.com/forums/u/kangrh007)\
**Post date:** [October 21, 2019, 7:40pm UTC](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/7 "2019-10-21T19:40:44Z")

</div>

_In reply to [shaygueta](https://verificationacademy.com/forums/t/use-of-a-bit-from-a-packed-array-as-a-ref-to-task/36522/6):_

I think you can pass the bit in packet array to a logic type variable first, sort of

logic a;  
a = packet\_array[0];  
#you can also change the data type before you call the task  
task MyTask(ref logic a)
