When Always comb and When Continuous Assignment

Skip to main content

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.

  • Digital Design and Embedded Programming
  • PLD, SPLD, GAL, CPLD, FPGA Design
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

difference between always and assign in verilog

  • Thread starter vead
  • Start date
Status
Not open for further replies.
  • #1
Joined
Nov 27, 2011
Messages
285
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
india
Activity points
3,815
I am confused I want to know what is difference between always and assign and where they use

program 1st


                                  
Code Verilog - [expand]
1 2 3 4 5                                            
                                              module                                              and2gate                                              (A,B,Y)                                              ;                                              input                                              A,B;                                              output                                              Y;                                              assign                                              Y=A&B;                                              endmodule                                            

program 2st


                                  
Code Verilog - [expand]
1 2 3 4 5 6 7 8 9                                            
                                              module                                              and2gate                                              (A,B,Y)                                              ;                                              input                                              A,B;                                              output                                              Y                                              reg                                              y                                              always                                              @                                              (AorB)                                              ;                                              begin                                              Y<=A&B;                                              end                                              endmodule                                            

which program is right please someone explain where we use always and assign syntax

Last edited by a moderator:
  • #2
  • #3
Joined
Nov 27, 2011
Messages
285
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
india
Activity points
3,815

I think assign is used for combination logic and always is used for sequential logic please clear my doubt
  • #4
Joined
Dec 15, 2011
Messages
828
Helped
365
Reputation
734
Reaction score
358
Trophy points
1,353
Location
Fremont, CA, USA
Activity points
6,967
An assign statement is usually used for combinational logic.Of course, if your technology allows it, you could model a latch or sequential logic out of a combinational feedback loop. But that is very rare.

An always block can readily be used for either. Whether it is combinational or sequential depends on how you trigger the execution of the block, as well as ordering of reads versus writes to variables within the same block and between different blocks. So a single always block could represent both kinds of logic at the same time.

SystemVerilog added three flavors of always blocks: always_comb, always_latch, and always_ff, to specify your intent and to report when what you've modeled doesn't match the intent.

  • #5
Joined
Nov 27, 2011
Messages
285
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
india
Activity points
3,815
I have posted two program which one is right
  • #6
Joined
Oct 31, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
16
  • #7
Joined
Dec 15, 2011
Messages
828
Helped
365
Reputation
734
Reaction score
358
Trophy points
1,353
Location
Fremont, CA, USA
Activity points
6,967
They are both functionally correct, except that you should not use '<= non-blocing assignment operators with combinational logic.
  • #8
Joined
Nov 19, 2009
Messages
243
Helped
71
Reputation
142
Reaction score
67
Trophy points
1,308
Location
United States
Activity points
3,730
+1 with dave_59. One very often does have non-blocking assignments within an always@ block because the block is generally executed on a clock or signal transition and not continuously.
An assign statement within a module is always/continuously made within the module.
If you don't need to qualify your combinational logic with synchronizing to a clock edge or other signal transition, it is generally preferred (to me anyway) to implement the combinational logic with the assign statement.
  • #9
In the present example, the continuous assignment variant seems preferable already by it's conciseness. A behavioral modelling style and procedural assignments are often suitable for complex combinational logic, using e.g. conditional, case and looping statements.

Behavioral constructs, either for combinational or registered logic, involve much of the elegance and coding efficiency of Verilog or VHDL.

Status
Not open for further replies.
  • Digital Design and Embedded Programming
  • PLD, SPLD, GAL, CPLD, FPGA Design

kinseyfored1936.blogspot.com

Source: https://www.edaboard.com/threads/difference-between-always-and-assign-in-verilog.302176/

0 Response to "When Always comb and When Continuous Assignment"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel