Verilog 多路复用子模块
我需要设计一个右移单元,有4个模块(逻辑、旋转、带进位旋转和算术移位)。我已经分别编写了每个模块,它们都可以工作,但我需要一个多路复用器来调用移位模块中的每个模块Verilog 多路复用子模块,verilog,Verilog,我需要设计一个右移单元,有4个模块(逻辑、旋转、带进位旋转和算术移位)。我已经分别编写了每个模块,它们都可以工作,但我需要一个多路复用器来调用移位模块中的每个模块 module lshr(a,lout); input [7:0]a; output [7:0]out; assign lout[7]=0; assign lout[6:0]= a[7:1]; endmodule module rshr(a,rout); input [7:0]a; output [7:0]ro
module lshr(a,lout);
input [7:0]a;
output [7:0]out;
assign lout[7]=0;
assign lout[6:0]= a[7:1];
endmodule
module rshr(a,rout);
input [7:0]a;
output [7:0]rout;
assign rout[7]=a[0];
assign rout[6:0]= a[7:1];
endmodule
module rcshr(a,cin,rcout);
input [7:0]a;
input cin;
output [7:0]rcout;
assign rcout[7]=cin;
assign rcout[6:0]= a[7:1];
endmodule
module ashr(a,aout);
input [7:0]a;
output [7:0]aout;
assign aout[7]=a[7];
assign aout[6:0]=a[7:1];
endmodule
module mux418bit(a,b,c,d,s0,s1,e);
input[7:0]a,b,c,d;
input s0,s1;
output[7:0]e;
module sru(a,cin,s0,s1,out);
input[7:0]a;
input cin
input s0,s1;
output[7:0]out;
????? i dont know what to do here!
endmodule
您需要做的是使用您在
sru
模块中创建为子模块的模块,即:
module sru(a,cin,s0,s1,out);
input[7:0]a;
input cin;
input s0,s1;
output [7:0]out;
wire [7:0] lshr_out, rshr_out, rcshr_out, ashr_out;
lshr m1(a, lshr_out);
rshr m2(a, rshr_out);
rcshr m3(a, cin, rcshr_out);
ashr m4(a, ashr_out);
mux418bit m5(lshr_out, rshr_out, rcshr_out, ashr_out, s0, s1, out);
endmodule
如您所见,您的四个模块(lshr
,rshr
,rcshr
,ashr
)被声明为sru
中的子模块(m1
,…,m5
)。这些模块的输出根据s0
和s1
值进行多路复用(在m5
子模块内部)(case
construct对此负责)
您可以检查此代码是否编译时没有任何错误
还有一件事,您的mux418bit
模块没有完成。您可能希望实现以下目标:
module mux418bit(a,b,c,d,s0,s1,e);
input[7:0]a,b,c,d;
input s0,s1;
output reg [7:0]e;
always @(*) begin
case({s0,s1})
2'b00 : e = a;
2'b01 : e = b;
2'b10 : e = c;
2'b11 : e = d;
endcase
end
endmodule
在无法使用case
construct的情况下:
module mux418bit(a,b,c,d,s0,s1,e);
input[7:0]a,b,c,d;
input s0,s1;
output [7:0]e;
assign e = ({s0,s1} == 2'b00) ? a :
({s0,s1} == 2'b01) ? b :
({s0,s1} == 2'b10) ? c : d;
endmodule
谢谢你的回答,但我的教授告诉我不要使用这个案例,而且。。。。我只需要添加一个多路复用器来指示输出,但我不知道如何@ZG:我对答案做了一点修改。您能在
mux418bit
模块内使用case
吗<代码>案例构造将被合成为多路复用器。不,对不起,我不擅长用verilog编程。这是她写的一个例子,让我们这样写代码。模块(a、b、s0、s1、out、cout、cin);输入[7:0]a,b;输入cin、s0、s1;输出[7:0]输出;输出电流;导线[7:0]e;MUX418位mux(8'b00000000,b,~b,8'b00000001,s0,s1,e);全加8位fa8(a、e、cin、cout、out);端模