10

I have read that use of nonblocking assignments is not allowed in Verilog functions. Can anyone suggest a plausible explanation for this?

2 Answers 2

10

The IEEE Std for Verilog (1364-2001), section "10.3.4 Function rules" states:

A function shall not have any nonblocking assignments.

The intention was for functions to be simple to evaluate in the Verilog event queue. If you need to advance time, use a task instead of a function.

Sign up to request clarification or add additional context in comments.

Comments

0

Try not to think about functions in Verilog like functions in C:

Functions in Verilog are designed to be a developer-friendly way to instantiate identical combinational logic in multiple places at once rather than having to write it over again / make a module for it. A lot of "newbies" to Verilog try to rationalize functions like they are C functions, and while they are "returning" a value, it is easier (and more correct) in the end to conceptualize them as blocks of combinational gates.

Note that this is different from a "task", which are more generally used for executing things "in order", which would probably be more useful in a testbench situation than a function

As you learn Verilog try not to rationalize the HDL you write as "code", because it is a different style of thinking.

EDIT: Took out some bad explanation on my part

6 Comments

In testbenches it still doesn't make sense to have blocking assignments in functions. Functions are NOT software functions, even in testbenches. While even in something like SystemVerilog testbenches can be very "software"-like, they still are representing hardware, if very abstractly.
You have the terminology wrong between blocking and nonblocking. And your rationale is doubtful. Functions are unte
... Functions are intended to work as in software in the first place.
Tasks and functions are different. Tasks are designed to execute "in order" like software. Functions act like combinational logic. Unless you are writing Verilog that only lives in simulator land this difference actually matters. (Fixed the confusion above)
The question wasn't specific to synthesis and verilog functions are clearly designed to mimic those from languages like C.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.