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] problem with conditional operator in verilog

Status
Not open for further replies.

arishsu

Member level 3
Member level 3
Joined
Sep 10, 2013
Messages
66
Helped
6
Reputation
12
Reaction score
6
Trophy points
8
Location
India
Visit site
Activity points
422
Is this syntax is right for 4:1 mux output?

assign Y=(S==0x)?((S==00)? I[0]:I[1]):(((S==1x)?((S==10)? I[2]:I[3]));

S is 2 bit reg(select line), I is 4 bit reg(input) and Y output.
 

Best get rid of the x don't cares. See this thread for some examples.

Personally I use something like this:
Code:
assign o= (s[0]==0)?((s[1]==0)?i[0]:i[1]):((s[1]==0)?i[2]:i[3]);
 
Best get rid of the x don't cares. See this thread for some examples.

Personally I use something like this:
Code:
assign o= (s[0]==0)?((s[1]==0)?i[0]:i[1]):((s[1]==0)?i[2]:i[3]);

A little formatting might make it more readable...


Code Verilog - [expand]
1
2
3
4
assign o = (s[0]==0) ? ([s[1]==0) ? i[0]   // 00
                                  : i[1])  // 10
                     : ((s[1]==0) ? i[2]   // 01
                                  : i[3]); // 11

 
A little formatting might make it more readable...

Fully agreed. I was just reciprocating laziness, and as such did a quick copy/paste from that other thread with the kind of code snippet I'd use. ;)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top