Reputation: 47
I was wondering if it were possible to have if statements, so for the ALU I am trying to build. I am passing values from a datapath test bench to a datapath, from the datapath into the ALU, and from the ALU back to the datapath. I am trying to create a control unit which will only pass values through a certain component if the corresponding control_ALU is activated.
Here is my verilog code :
module ALU (
input en_ALU, clk_ALU,
input [31:0] inputA, inputB, control_ALU,
output [31:0] resultc
);
wire [31:0] res_out;
always @(control_ALU)
begin
if(control_ALU[1]) begin
andLogic andLogic_component(
.dataA (inputA),
.dataB (inputB) ,
.resultA (res_out)
);
end
if(control_ALU[2]) begin
negate m0(
.inputnegate (inputA),
.resultnegate (res_out)
);
end
end
reg64bit z(
.clk(clk_ALU) ,
.clr(clr),
.enable(en_ALU),
.inputd(res_out),
.outputq(resultc)
);
endmodule
Upvotes: 0
Views: 1633
Reputation: 239
Not sure you can put the instance in IF statement.
But I know you can declare your instance first, then give each of them a different output name, then use CASE statement or IF statement to select different output as your top module ALU output.
case(funct)
3'b000: //ALU control signal
ALU_out = add;
3'b001:
ALU_out = sub;
3'b010:
ALU_out = andlogic;
...
...
...
endcase
Remember to give a default if the case statement is not complete.
Hope this is helpful. :-)
Upvotes: 1