EDAboard.com | EDAboard.eu | EDAboard.de | EDAboard.co.uk | RTV forum PL | NewsGroups PL

DIfference between function and procedure

Ask a question - edaboard.com

elektroda.net NewsGroups Forum Index - VHDL Language - DIfference between function and procedure

Don Otknow
Guest

Thu Mar 03, 2011 9:23 pm   



Hello,

I've never really understood the difference between a function and a
procedure in VHDL. I've read that a function returns 1 value whereas a
procedure can return multiple values? Could someone elucidate this for
me?

Also, I am confused about the scope of signals. If I declare a signal
within an architecture, does the scope of this signal extend to
functions declared within processes in the architecture? If not, is
there a way to do this without passing the signals? I would like to
call functions in a way resembling scripts that allowed for greater
code readability.

Thanks,
Don

Brian Drummond
Guest

Thu Mar 03, 2011 9:37 pm   



On Thu, 3 Mar 2011 11:23:44 -0800 (PST), Don Otknow <donald.otknow_at_gmail.com>
wrote:

Quote:
Hello,

I've never really understood the difference between a function and a
procedure in VHDL. I've read that a function returns 1 value whereas a
procedure can return multiple values? Could someone elucidate this for
me?

Same as in just about any language except the C family.

Function follows the basic pattern of a mathematical function; it (should) have
no side-effects and it returns a value. It is an abstraction over an expression;
it shouldn't change any term in that expression.

Procedure returns NO values (though some of its parameters may have OUT or INOUT
modes, which can be used to communicate results to the caller. ) It is an
abstraction over a statement (or block, i.e. sequence of statements).

Quote:
Also, I am confused about the scope of signals. If I declare a signal
within an architecture, does the scope of this signal extend to
functions declared within processes in the architecture?

Yes.
But please don't assign to that signal within a function!
You can assign to that signal within a procedure.

Functions and procedures (collectively, subprograms) can see the scope in which
they are declared - plus their own local variables. So they can not only see
signals outside the process, but any variables declared in the process (before
their own declaration!)

Parameters passed to the function or procedure come in useful when you want
different calls of the procedure to operate on DIFFERENT signals.

If you declare a library of useful subprograms in a package, you will find the
visibility rules are different there, and you will normally pass parameters to
them. One useful pattern is to keep the real subprograms there, and declare
simple (e.g. parameterless) wrapper subprograms within your process, which
simply call the real ones with appropriate parameters

Quote:
I would like to
call functions in a way resembling scripts that allowed for greater
code readability.

Good idea.
But also; to allow programming - and hardware generation - at a higher level
than VHDL is typically used for.

- Brian

Don Otknow
Guest

Thu Mar 03, 2011 11:34 pm   



On Mar 3, 12:37 pm, Brian Drummond <brian_drumm...@btconnect.com>
wrote:
Quote:
On Thu, 3 Mar 2011 11:23:44 -0800 (PST), Don Otknow <donald.otk...@gmail.com
wrote:

Hello,

I've never really understood the difference between a function and a
procedure in VHDL. I've read that a function returns 1 value whereas a
procedure can return multiple values? Could someone elucidate this for
me?

Same as in just about any language except the C family.

Function follows the basic pattern of a mathematical function; it (should) have
no side-effects and it returns a value. It is an abstraction over an expression;
it shouldn't change any term in that expression.

Procedure returns NO values (though some of its parameters may have OUT or INOUT
modes, which can be used to communicate results to the caller. ) It is an
abstraction over a statement (or block, i.e. sequence of statements).

Also, I am confused about the scope of signals. If I declare a signal
within an architecture, does the scope of this signal extend to
functions declared within processes in the architecture?

Yes.
But please don't assign to that signal within a function!
You can assign to that signal within a procedure.

Functions and procedures (collectively, subprograms) can see the scope in which
they are declared - plus their own local variables. So they can not only see
signals outside the process, but any variables declared in the process (before
their own declaration!)

Parameters passed to the function or procedure come in useful when you want
different calls of the procedure to operate on DIFFERENT signals.

If you declare a library of useful subprograms in a package, you will find the
visibility rules are different there, and you will normally pass parameters to
them. One useful pattern is to keep the real subprograms there, and declare
simple (e.g. parameterless) wrapper subprograms within your process, which
simply call the real ones with appropriate parameters

I would like to
call functions in a way resembling scripts that allowed for greater
code readability.

Good idea.
But also; to allow programming - and hardware generation - at a higher level
than VHDL is typically used for.

- Brian

Thanks a lot Brian! Your explanations are very helpful.

elektroda.net NewsGroups Forum Index - VHDL Language - DIfference between function and procedure

Ask a question - edaboard.com

Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
RTV map EDAboard.com map News map EDAboard.eu map EDAboard.de map EDAboard.co.uk map Opony