我正在制作一个遵循MIPS装配说明的单循环CPU,并且想知道如何清理原理图。例如,我有几个不同的模块一起实例化,如下面的代码所示。现在,当它出现在原理图中时,所有模块都是它们自己的块,可以通过单击左上角打开它。
我不需要在我的环境下如何做到这一点的代码,而是一个简单的语法,展示如何链接不同的模块,并在较大的模块下“嵌套”较小的模块。如果这是可能的话。
谢谢
module CPU_Wire(clk,clrn);
input clk,clrn;
//programCounter
wire [31:0] pcinw; //wire going from the multiplexer2 output to the input of pc
wire [31:0] pcoutw; //from pc to the instruction fetch input
wire clkw,clrnw; //wires for clk and clrn
wire [31:0] pc1; //wire going from PC to instructionFetch without the +4
//instructionFetch
wire [5:0] opw,funcw;
wire [4:0] rsw,rtw,rdw; //decoding output wires
wire [31:0] saw; //need bigger wire for sign extension of sa
wire [15:0] immw;
wire [31:0] immoutw; //for immediate output
wire [25:0] addrw; //for address for jump instruction
//regrtMultiplexer
wire [4:0] regrtOw;
//immediateMultiplexer
wire [31:0] immMuloutw;
//ControlUnit
wire [1:0] pcsrcw;
wire [3:0] alucw;
wire shiftw,wregw,m2regw,aluimmw,sextw,regrtw,wmemw; //Control Unit output
wire [31:0] qaw,qbw; //regfile output
wire [31:0] muloutw; //multiplexer output
//ALU
wire [31:0] rw; //ALU output
wire zw; //ALU zero flag
//DataMem
wire [31:0] doMulw;
//Instantiate all modules
programCounter pc
(
//input
.clk (clk ),
.clrn (clrn ),
.pcin (pcinw ),
//output
.pcout (pcoutw ),
.pc (pc1 )
);
instructionFetch iF
(
//input
.pc (pc1 ),
//output
.op (opw ),
.func (funcw ),
.rs (rsw ),
.rt (rtw ),
.rd (rdw ),
.sa (saw ),
.imm (immw ),
.addr (addrw )
);
regrtMultiplexer rM
(
//input
.rd (rdw ),
.rt (rtw ),
.regrt (regrtw ),
//output
.regrtO (regrtOw)
);
signextend se
(
.sext (sextw ),
.immin (immw ),
.immout (immoutw )
);
controlUnit cu
(
//input
.op (opw ),
.func (funcw ),
.z (zw ),
//output
.pcsrc (pcsrcw ),
.aluc (alucw ),
.wreg (wregw ),
.shift (shiftw ),
.wmem (wmemw ),
.m2reg (m2regw ),
.sext (sextw ),
.regrt (regrtw ),
.aluimm (aluimmw)
);
regfile rf
(
//input
.clk (clk ),
.clrn (clrn ),
.rna (rsw ),
.rnb (rtw ),
.wn (regrtOw),
.d (doMulw ),
.we (wregw ),
//output
.qa (qaw ),
.qb (qbw )
);
immediateMultiplexer iM
(
//input
.aluimm (aluimmw),
.qb (qbw ),
.immoutI (immoutw),
//output
.immMulout (immMuloutw)
);
ShiftMultiplexer m1
(
//input
.qa (qaw ),
.sa (saw ),
.shift (shiftw ),
//output
.mulout (muloutw)
);
ALU alu
(
//input
.aluc (alucw ),
.a (muloutw ),
.b (immMuloutw ),
//output
.r (rw ),
.z (zw )
);
DataMem DM
(
//input
.a (rw ),
.di (qbw ),
.we (wmemw ),
.m2reg (m2regw ),
.clk (clk ),
.clrn (clrn ),
//output
.doMul (doMulw )
);
multiplexer2 m2
(
//input
.pcsrcI (pcsrcw ),
.pcoutI (pcoutw ),
.immout (immoutw),
.qa (qaw ),
.addr (addrw ),
//Output
.pcinO (pcinw )
);
endmodule
答案 0 :(得分:0)
模块用于描述模型的块以及这些块的层次结构。每个这样的模块都有一个端口列表,用于定义块的输入和输出。
块在其他块内实例化以表示层次结构。它们的端口在模块中连接,该模块通过此父模块中定义的变量实例化其他模块。
所以,这个想法如下。据说你有2个模块
module buf(input inp, output out);
assign out = inp;
endmodule
module inv(input inp, output out);
assign out = ~inp;
endmodule
据说你想连锁缓冲区和inverer。你需要一个能够实例化和连接它们的顶级模块
module top(input inp, output out);
wire bufout;
buf buf(.inp(inp), .out(bufout));
inv inv(.inp(bufout), .out(out));
endmodule
因此,在上面的例子中,两个模块'buf'和'inv'都相应地实例化为'buf'和'inv'实例。 'buf'的输入'inp'连接到'top'的'inp'输入信号。它的输出连接到顶部模块内定义的'bufout'线,该线也是'inv'的输入。 'inv'的输出连接到'top'的输出。
其余取决于模型中使用的每个模块的端口数量和类型。