What can you do if you need to return two or more variables from a function?

#1

SystemVerilog functions can have inputs and outputs. Using outputs is useful in case you want to return a queue from a function (or some other complex type), or in case you want to return two or more different variables from the function.

Example: Let’s say that you have a queue of numbers, and you want to return a queue of only even numbers, and you also need the value of the first element in the queue of even numbers.

What can you do if you need to return two or more variables from a function?

Calling a function:

Read more on page 105 of this reference manual: http://ece.uah.edu/~gaede/cpe526/SystemVerilog_3.1a.pdf

#2

Another option is to use passing the arguments by reference. Let’s say you need the second and last element in an array/queue.

Calling a function:

EDA Playground example: https://www.edaplayground.com/x/YM8M

Contact Us

Please, enter your details below. We will get back to you as fast as we can.

This website uses cookies to ensure you get the best experience on our website.

Get Cogita

Please, enter your details below. We will get back to you as fast as we can.

Thank you!

We will get in touch soon.

Get a Quote

Please, enter your details below. We will get back to you as fast as we can.