我想知道是否有可能有if语句,所以对于我正在尝试构建的ALU。我将值从数据路径测试平台传递到数据路径,从数据路径传递到ALU,再从ALU传递回数据路径。我正在尝试创建一个控制单元,如果相应的control_ALU被激活,该控制单元将仅通过某个组件传递值。
下面是我的verilog代码:
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发布于 2015-02-26 00:11:51
不确定是否可以将实例放入IF语句中。
但我知道你可以先声明你的实例,然后给每个实例一个不同的输出名称,然后使用CASE语句或IF语句来选择不同的输出作为顶级模块ALU的输出。
case(funct)
3'b000: //ALU control signal
ALU_out = add;
3'b001:
ALU_out = sub;
3'b010:
ALU_out = andlogic;
...
...
...
endcase如果case语句不完整,请记住给出一个默认值。
希望这能对你有所帮助。:-)
https://stackoverflow.com/questions/28710698
复制相似问题