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.

conditional assignment statement

Status
Not open for further replies.

sree205

Advanced Member level 1
Joined
Mar 13, 2006
Messages
453
Helped
58
Reputation
116
Reaction score
25
Trophy points
1,308
Activity points
4,420
Hi,
can we use the conditional assignment statement inside always blocks like the example below ??

module ex(clk,x,a,b,y)
input a,b,x;
output y;
reg y;

always@(posedge clk)
y = x ? a : b ;

endmodule
 

It wrote not correctly!!!

assign in always not use!!!!

need write:
OR
assign y = x ? a : b ;

OR

always@(posedge clk)
if (x)
y = a;
else
y = b ;

OR

always@(posedge clk)
case (x)
1'b1 : y = a;
1'b0 : y = b ;
endcase
 

sree205 said:
Hi,
can we use the conditional assignment statement inside always blocks like the example below ??

module ex(clk,x,a,b,y)
input a,b,x;
output y;
reg y;

always@(posedge clk)
y = x ? a : b ;

endmodule

That should work. Did you see any issues?

Ajeetha, CVC
Contemporary Verification Consultants Pvt Ltd. http://www.noveldv.com
* A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5 http://www.systemverilog.us/
* SystemVerilog Assertions Handbook
* Using PSL/Sugar
 

Think this in more hardware way:

When see a rising edge, then a mux is created, i.e., the control line of the mux is also determined by the rising edge.
 

may b its nt synthesiable
 

shiv_emf said:
may b its nt synthesiable

AFAIK, it is perfectly synthesizable.

Ajeetha,CVC
* New Book: A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
http://www.systemverilog.us/
* SystemVerilog Assertions Handbook, 2005 ISBN 0-9705394-7-9
* Using PSL/SUGAR
Design Verification Consultant,
Contemporary Verification Consultants Private Limited,
Bangalore, India, http://www.noveldv.com
 

hi aji, you are absolutely right. its synthesizable and its easy on the eyes while debugging.
 

Above code simulates and synthesizes
regards,
ramana
 

in assign statement
lhs is continuously assigned
but if we use it in an always block
it is a crime because , always block will be executed only at athe posedge of an event hence we may miss the values
 

yes, you can do this like this.
it is a mux followed a register.
 

sree205 said:
hi aji, you are absolutely right. its synthesizable and its easy on the eyes while debugging.
yes, it's absolutely synthesizable.but , this kind of coding style may not acceptably
in many company.
useing the noblocking assignment would be a good choice when you need a dff.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top