如何将一个模块的输出用作verilog中另一个模块的输入?
How to give the output of one module to be used as an input by another module in verilog?
//code for alu
module alu(result,A,B,control);
output reg [0:31] result;
input [0:31] A;
input [0:31]B;
input [0:5]control;
always @(*)
begin
case(control)
//F0 f1 ena enb inva inc fun
6'b011000:result=A;
6'b010100:result=B;
6'b011010:result=~A;
6'b101100:result=~B;
6'b111100:result=A+B;
6'b111101:result=A+B+1;
6'b111001:result=A+1;
6'b110101:result=B+1;
6'b111111:result=B-A;
6'b110110:result=-A;
6'b001100:result=A&B;
6'b011100:result=A|B;
6'b010000:result=0;
6'b110001:result=1;
6'b110010:result=-1;
default:result=0;
endcase
end
endmodule
//code for shifter
module shifter(C,sll,sr,Alu_Out,clk);
output reg [0:31]C;
input clk;
input sll,sr;
input [0:31]Alu_Out;
integer i;
always @(posedge clk)
begin
if(sll==1'b1 && sr==1'b0)
begin
for(i=0;i<24;i=i+1)
begin
C[i]<=Alu_Out[i+8];
end
for(i=31;i>23;i=i-1)
begin
C[i]<=0;
end
end
if(sll==1'b0 && sr==1'b1)
begin
C[0]<=Alu_Out[0];
for(i=0;i<31;i=i+1)
begin
C[i+1]<=Alu_Out[i];
end
end
end
endmodule
我正在尝试使用 verilog 实现 IJVM,即 Tanenbaum 教科书中给出的,为此我正在制作 ALU 单元和移位寄存器,我已经分别制作了 ALU 和移位寄存器单元,现在我想将两者结合起来单位,即我想将 ALU 的输出,即 "result"(请参考代码)作为移位器的输入,即 "Alu_out"(请参考代码)。并得到最终的输出形式移位器即 "C"(请参阅代码)。任何人都可以帮助解决这个问题以及如何编写相同的测试平台。
在你的模块移位器中调用模块 alu
module shifter(C,sll,sr,Alu_Out,clk,A,B,control);
output reg [0:31]C;
input clk;
input sll,sr;
input [0:31] A;
input [0:31]B;
input [0:5]control;
input [0:31]Alu_Out;
alu first_call(Alu_out,A,B,control);
您的休息码
第一个模块的结果值将存储在 alu_out 中,并在移位器模块本身中提供输入。
您也可以使 alu 函数,因为您只需要一个输出作为结果。
//code for alu
module alu(result,A,B,control);
output reg [0:31] result;
input [0:31] A;
input [0:31]B;
input [0:5]control;
always @(*)
begin
case(control)
//F0 f1 ena enb inva inc fun
6'b011000:result=A;
6'b010100:result=B;
6'b011010:result=~A;
6'b101100:result=~B;
6'b111100:result=A+B;
6'b111101:result=A+B+1;
6'b111001:result=A+1;
6'b110101:result=B+1;
6'b111111:result=B-A;
6'b110110:result=-A;
6'b001100:result=A&B;
6'b011100:result=A|B;
6'b010000:result=0;
6'b110001:result=1;
6'b110010:result=-1;
default:result=0;
endcase
end
endmodule
//code for shifter
module shifter(C,sll,sr,Alu_Out,clk);
output reg [0:31]C;
input clk;
input sll,sr;
input [0:31]Alu_Out;
integer i;
always @(posedge clk)
begin
if(sll==1'b1 && sr==1'b0)
begin
for(i=0;i<24;i=i+1)
begin
C[i]<=Alu_Out[i+8];
end
for(i=31;i>23;i=i-1)
begin
C[i]<=0;
end
end
if(sll==1'b0 && sr==1'b1)
begin
C[0]<=Alu_Out[0];
for(i=0;i<31;i=i+1)
begin
C[i+1]<=Alu_Out[i];
end
end
end
endmodule
我正在尝试使用 verilog 实现 IJVM,即 Tanenbaum 教科书中给出的,为此我正在制作 ALU 单元和移位寄存器,我已经分别制作了 ALU 和移位寄存器单元,现在我想将两者结合起来单位,即我想将 ALU 的输出,即 "result"(请参考代码)作为移位器的输入,即 "Alu_out"(请参考代码)。并得到最终的输出形式移位器即 "C"(请参阅代码)。任何人都可以帮助解决这个问题以及如何编写相同的测试平台。
在你的模块移位器中调用模块 alu
module shifter(C,sll,sr,Alu_Out,clk,A,B,control);
output reg [0:31]C;
input clk;
input sll,sr;
input [0:31] A;
input [0:31]B;
input [0:5]control;
input [0:31]Alu_Out;
alu first_call(Alu_out,A,B,control);
您的休息码
第一个模块的结果值将存储在 alu_out 中,并在移位器模块本身中提供输入。
您也可以使 alu 函数,因为您只需要一个输出作为结果。