0
\$\begingroup\$

For the below image, why does assign out = a&~sel + b&sel only output one instead of the ref solution below? Is there any way to do this problem with assign only?

enter image description here

enter image description here

\$\endgroup\$
0

2 Answers 2

2
\$\begingroup\$

Looks like I'm too new to comment here, but I wanted to expand on the previous answer. With one-hot mux selects, that you want to synthesize into an and-or tree, you can't use the ternary conditional operator. You have to use the replication operator. This is one thing that vhdl (I think) does better than verilog.

assign foo = in1 & {WIDTH{sel1}} | in0 & {WIDTH{sel0}} ;

If the original questioner tries something like this to replicate the select, it should work. But ternary conditional is preferred. So is if/else inside an always block.

\$\endgroup\$
1
\$\begingroup\$

Could that be because the sel is just one bit wide?

If you wanted to use that, you'd probably have to extend the sel to the same width as the other inputs.

Quite frankly, I don't know why'd you want to do it that way (the (a & ~s) | (b & s) way), really. Just use the ternary operator as suggested - it really is easier to read and less cluttered. (Sure it may be confusing at first, but you'll get used to it quickly.)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.