我有两个几乎相同的内存芯片实现,除了一个可以工作,另一个,当我在硬件模拟器中使用 Memory.tst 进行测试时,当程序希望我按 Y 键时给出一个无限循环。
WORKS的实现是:
CHIP Memory {
IN in[16], load, address[15];
OUT out[16];
PARTS:
// RAM
// [00]0 0000 0000 0000
// [01]1 1111 1111 1111
// Screen
// [10]0 0000 0000 0000
// [10]0 1111 1111 1111
// Keyboard
// [11]0 0000 0000 0000
DMux4Way(in=load, sel=address[13..14], a=ram1, b=ram2, c=loadScreen, d=ignored);
Or(a=ram1, b=ram2, out=loadRam);
RAM16K(in=in, load=loadRam, address=address[0..13], out=outRam);
Screen(in=in, load=loadScreen, address=address[0..12], out=outScreen);
And(a=address[13], b=address[14], out=canBeKbd);
Or8Way(in=address[0..7], out=anyOne07);
Or8Way(in=address[5..12], out=anyOne512);
Or(a=anyOne07, b=anyOne512, out=anyOne012);
Not(in=anyOne012, out=allZero012);
And(a=canBeKbd, b=allZero012, out=isKbd);
Keyboard(out=kdb);
Mux16(a=false, b=kdb, sel=isKbd, out=outKbd);
Mux4Way16(a=outRam, b=outRam, c=outScreen, d=outKbd, sel=address[13..14], out=out);
}
不工作的实现是:
CHIP Memory {
IN in[16], load, address[15];
OUT out[16];
PARTS:
// RAM
// [00]0 0000 0000 0000
// [01]1 1111 1111 1111
// Screen
// [10]0 0000 0000 0000
// [10]0 1111 1111 1111
// Keyboard
// [11]0 0000 0000 0000
DMux4Way(in=load, sel=address[13..14], a=ram1, b=ram2, c=loadScreen, d=canBeKbd);
Or(a=ram1, b=ram2, out=loadRam);
RAM16K(in=in, load=loadRam, address=address[0..13], out=outRam);
Screen(in=in, load=loadScreen, address=address[0..12], out=outScreen);
Or8Way(in=address[0..7], out=anyOne07);
Or8Way(in=address[5..12], out=anyOne512);
Or(a=anyOne07, b=anyOne512, out=anyOne012);
Not(in=anyOne012, out=allZero012);
And(a=canBeKbd, b=allZero012, out=isKbd);
Keyboard(out=kdb);
Mux16(a=false, b=kdb, sel=isKbd, out=outKbd);
Mux4Way16(a=outRam, b=outRam, c=outScreen, d=outKbd, sel=address[13..14], out=out);
}
第二个实现的唯一区别是我从第一个 DMux 获得了 canBeKbd。这应该有效,但它没有。我会很高兴有人能告诉我为什么。
通过给定测试的其他实现将是:
CHIP Memory {
IN in[16], load, address[15];
OUT out[16];
PARTS:
// RAM
// [00]0 0000 0000 0000
// [01]1 1111 1111 1111
// Screen
// [10]0 0000 0000 0000
// [10]0 1111 1111 1111
// Keyboard
// [11]0 0000 0000 0000
DMux4Way(in=load, sel=address[13..14], a=ram1, b=ram2, c=loadScreen, d=loadKbd);
Or(a=ram1, b=ram2, out=loadRam);
RAM16K(in=in, load=loadRam, address=address[0..13], out=outRam);
Screen(in=in, load=loadScreen, address=address[0..12], out=outScreen);
Keyboard(out=outKbd);
Mux4Way16(a=outRam, b=outRam, c=outScreen, d=outKbd, sel=address[13..14], out=out);
}
但是我不能使用第三种实现,因为我不会测试所有前 12 位都是 0。因为键盘内存位置仅为 0011 0000 0000 0000 (0x6000)。