-1

例如,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.
4

1 回答 1

1

您是否尝试这样做以进行综合或仿真?一个简单的技巧是使用 $fscanf 并有一些初始化代码迭代文件,将文件中的一行复制到各种触发器中。当然,对于综合来说,这是行不通的。我可以问你为什么不想只使用 reg 吗?

于 2013-05-27T16:29:03.830 回答