Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] simple question: using verilog can one have an if statment inside a function?

Status
Not open for further replies.

aelbad

Junior Member level 1
Junior Member level 1
Joined
Feb 3, 2014
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
132
I just wanted to know if it is not a problem using an if statement inside a function to assign a value to the function output (this should be a simple question :))
 

I just wanted to know if it is not a problem using an if statement inside a function to assign a value to the function output (this should be a simple question :))

Which programming language? If you are talking about verilog, you can't use if statement outside always loop. You can use conditional operator to assign a value to a variable outside always loop.
 
  • Like
Reactions: aelbad

    aelbad

    Points: 2
    Helpful Answer Positive Rating
Which programming language? If you are talking about verilog, you can't use if statement outside always loop. You can use conditional operator to assign a value to a variable outside always loop.

I am talking about verilog. but still one can use an if statement inside a task as well then why not inside a function?

now we have two contradictory replies :D by arishsu and rberek :thinker:
 
Last edited by a moderator:

It would be very odd not to be able to use if-else statements in a function. But whether it is synthesisable depends on the function behaviour.
 

Verilog functions are used to save typing, and can't contain any timing statements (i.e. #, fork-join, etc), but they can contain if-else statements. Consult the Language Reference Manual to see for yourself.

Functions are placed inside of always blocks, so I am not sure why arishsu was concerned that they fell outside of them.

I forgot to add that I currently am using many functions that contain if-else statements in my current project and they simulate and synthesize just fine.

r.b.
 
  • Like
Reactions: aelbad

    aelbad

    Points: 2
    Helpful Answer Positive Rating
now we have two contradictory replies :D by arishsu and rberek :thinker:

I never mentioned function anywhere. In fact I didn't notice that 'function' word. Sorry for the mistake.

Functions are placed inside of always blocks, so I am not sure why arishsu was concerned that they fell outside of them.
r.b.

Completely agree with that.
 

now we have two contradictory replies :D by arishsu and rberek
Because unlike rberek, arishsu hasn't been using Verilog at work for years. Hence the contradictory replies...one from an experienced Verolog coder and one from presumably a student based on their previous posts.
 
  • Like
Reactions: aelbad

    aelbad

    Points: 2
    Helpful Answer Positive Rating
Thank you everyone for your helpful quick support, I really appreciate it.:thumbsup:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top