diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-08-16 11:54:23 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-08-16 11:54:23 +0800 |
commit | 9542deeb483a00b6fabed7574720926ce97d7511 (patch) | |
tree | 0f2c1f72c03dd4693fd59df67544d2a4dddc5494 /projects/05/Memory.hdl | |
parent | 9c0cb1d1c32724fc95ac9548e4f8d873d3adaccc (diff) |
Projects, 01-06 completed
Diffstat (limited to 'projects/05/Memory.hdl')
-rw-r--r-- | projects/05/Memory.hdl | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/projects/05/Memory.hdl b/projects/05/Memory.hdl new file mode 100644 index 0000000..c551d74 --- /dev/null +++ b/projects/05/Memory.hdl @@ -0,0 +1,43 @@ +// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: projects/05/Memory.hdl
+
+/**
+ * The complete address space of the Hack computer's memory,
+ * including RAM and memory-mapped I/O.
+ * The chip facilitates read and write operations, as follows:
+ * Read: out(t) = Memory[address(t)](t)
+ * Write: if load(t-1) then Memory[address(t-1)](t) = in(t-1)
+ * In words: the chip always outputs the value stored at the memory
+ * location specified by address. If load==1, the in value is loaded
+ * into the memory location specified by address. This value becomes
+ * available through the out output from the next time step onward.
+ * Address space rules:
+ * Only the upper 16K+8K+1 words of the Memory chip are used.
+ * Access to address>0x6000 is invalid. Access to any address in
+ * the range 0x4000-0x5FFF results in accessing the screen memory
+ * map. Access to address 0x6000 results in accessing the keyboard
+ * memory map. The behavior in these addresses is described in the
+ * Screen and Keyboard chip specifications given in the book.
+ */
+
+CHIP Memory {
+ IN in[16], load, address[15];
+ OUT out[16];
+
+ PARTS:
+ // RAM16K
+ Not(in=address[14], out=notaddr14);
+ And(a=notaddr14, b=load, out=loadRAM16K);
+ RAM16K(in=in, load=loadRAM16K, address=address[0..13], out=outRAM16K);
+ // Screen
+ Not(in=address[13], out=notaddr13);
+ And(a=notaddr13, b=address[14], out=screenaddr);
+ And(a=screenaddr, b=load, out=loadScreen);
+ Screen(in=in, load=loadScreen, address=address[0..12], out=outScreen);
+ // Keyboard
+ Keyboard(out=outKeyboard);
+ Mux16(a=outScreen, b=outKeyboard, sel=address[13], out=scrkbd);
+ Mux16(a=outRAM16K, b=scrkbd, sel=address[14], out=out);
+}
|