Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
Can't you just define intermediate wires? Then you can also give your intermediate signals intelligible names, further improving maintainability... – vicatcu Apr 10 '12 at 12:22
2  
Also, many people avoid it in C-family programming languages, but to be proficient in Verilog you must become familiar with the ternary operator ?:. – The Photon Apr 10 '12 at 15:31

1 Answer

up vote 1 down vote accepted

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
share|improve this answer
The problem is that I cannot make it a reg because it is an inout port. – Randomblue Apr 10 '12 at 12:20
I've edited. Note that you shouldn't be using inout ports for internal connections anyway. – avakar Apr 10 '12 at 12:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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