I'm sure it does assign something to z
. The problem is that you are trying to assign too much to z
.
Each assign
statement represents some hardware, which in this case drives the wire
z
. So, you are driving z
4 times in parallel from 4 separate lumps of hardware. If you like, you have a short circuit. (Remember Verilog is a hardware description language. You are designing hardware here, not writing software. If you assign to a wire from more than one place, you have shorted the outputs of some lumps of hardware together.)
I notice there is an input [2:0] op
. This looks like homework to me and I guess you have been asked to design an ALU. An ALU is a lump of hardware (combinational logic in this case) that can perform various operations on it's inputs (its operands), which in this case are a
and b
. Which operation it performs needs to be selected by some other control input, which in this case is almost certainly supposed to be op
.
So, you need some code that tests op
and drives z
with either a+b
, a-b
, a&b
or a|b
. The obvious construct to me for this job is a case
statement:
case (op)
3'b000:
z = // some expression, eg a + b, it depends on what op code 000 is supposed to mean
3'b001:
z = // some other expression here
// etc etc
default: // perhaps...
z = // ...something to drive z if none of the other branches are used
endcase
A case
statement should go inside an always
block. As I suspect this is homework, I won't feed you the answer, I'll let you work out how to do that.
Finally, I see that op
is 3 bits wide. This suggests that you ALU has more than 4 different operations to carry out. I also see there is an ex
output, which presumably needs to do something.