例如,reg [3:0] RAM [0:31];
我没有使用我自己的模块,尝试使用硬连线的 FlipFlopMod。
这就是我想要做的(但你会看到它显然不起作用):
module mem_mod(addr, mem_out);
input [4:0] addr; // 5-bit addr bus
output [3:0] mem_out; // 4-bit inst/data out
// a real flip flop instead of using reg.
FlipFlopMod_4bit RAM [0:31] (1/*enabled*/, 4'b1111, q, nq); // # of nibbles
assign mem_out = RAM[addr]; // change this to an AND selector.
// read binary code into RAM, prepare inst.txt 1st
initial $readmemb("inst.txt", RAM);
endmodule
// Gated Flip Flop
module FlipFlopMod_1bit(clk, d, q, nq);
input clk, d;
output q, nq;
wire and0, and1, d_inv;
not(d_inv, d); // d and d_inv are someties referred to as R and S, respectively.
// these two and gates cause the input to be latched only when clk
// (enable) is high.
and(and0, d, clk);
and(and1, clk, d_inv);
// These nor gates are the actual flipflop/latch.
nor(nq, and0, q);
nor(q, nq, and1);
endmodule
// 4 bit gated flip flop made using 1 bit gated flip flops.
module FlipFlopMod_4bit(clk, d, q, nq);
input clk;
input [3:0] d;
output [3:0] q, nq;
FlipFlopMod_1bit latch3 (clk, d[3], q[3], nq[3]);
FlipFlopMod_1bit latch2 (clk, d[2], q[2], nq[2]);
FlipFlopMod_1bit latch1 (clk, d[1], q[1], nq[1]);
FlipFlopMod_1bit latch0 (clk, d[0], q[0], nq[0]);
endmodule
这是我开始的地方,使用reg
(这有效):
module mem_mod(addr, mem_out);
input [4:0] addr; // 5-bit addr bus
output [3:0] mem_out; // 4-bit inst/data out
reg [3:0] RAM [0:31]; // # of nibbles
assign mem_out = RAM[addr];
// read binary code into RAM, prepare inst.txt 1st
initial $readmemb("inst.txt", RAM);
endmodule
如您所见,我不太确定如何将文件中的每条 4 位数据读取到我的自定义触发器数组中,以便我的每个触发器保持不同的值,就像reg
示例一样。我想我可能只对 32 个触发器进行硬编码,并对每个参数中的值进行硬编码,而不是读取文件,但这并不好玩!
我从 (inst.txt) 读取的文件如下所示:
0001
0011
1000
0011
...
...
... etc, 32 lines total.