3
\$\begingroup\$

I have a wire to which I assign a complex right-hand-side expression with lots of bitwise operations. This right-hand-side expression is quickly becoming long and hard to maintain.

Is there a way I could replace the bitwise operations by if/else or case statements to help readability and maintability?

asked Apr 10, 2012 at 12:17
\$\endgroup\$
2
  • \$\begingroup\$ Can't you just define intermediate wires? Then you can also give your intermediate signals intelligible names, further improving maintainability... \$\endgroup\$ Commented Apr 10, 2012 at 12:22
  • 2
    \$\begingroup\$ Also, many people avoid it in C-family programming languages, but to be proficient in Verilog you must become familiar with the ternary operator ?:. \$\endgroup\$ Commented Apr 10, 2012 at 15:31

1 Answer 1

4
\$\begingroup\$

Sure you can, just use the always @(*) construct (you need to make it a reg). You can handle inout ports easily too.

reg res;
assign inout_port = dir_out? res: 1'bz;
always @(*) begin
 if (x == 42 && y != z)
 res = 10;
 else
 res = y * 12;
end
answered Apr 10, 2012 at 12:19
\$\endgroup\$
2
  • \$\begingroup\$ The problem is that I cannot make it a reg because it is an inout port. \$\endgroup\$ Commented Apr 10, 2012 at 12:20
  • \$\begingroup\$ I've edited. Note that you shouldn't be using inout ports for internal connections anyway. \$\endgroup\$ Commented Apr 10, 2012 at 12:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.